Have a template class:
class Foo <T> {
private T bar;
public Foo(T bar) {
this.bar = bar;
}
}
Have an interface:
interface SomeInterface {
public void boom();
}
I want Foo
to only accept types of classes that implement the interface SomeInterface
.
Intuitively, I wanted something like this:
class Foo <T implements SomeInterface>
But apparently this doesn't work.
Is it possible for a template class to only accept implementers of a specific interface?
This is because I want to call certain methods on this.bar
. Methods that happen to be defined in SomeInterface
.