I've got a class Foo<T>. How can I say that I want T to be some class implementing BarInterface? Writing simply class Foo<T implements BarInterface> doesn't compile.
1 Answer
Use extends instead of implements.
4 Comments
Andreas Dolk
... if I had a compiler at hand I could test it right away: shouldn't it be
class Foo<? extends BarInterface> - extends is a WildcardBound ...helpermethod
+1 One note to add: Extends in the context of Generics has both the meaning of 'extends' AND 'implements', which I found quite confusing in the beginning.
Konrad Rudolph
@Andreas: no, it doesn’t work only on wildcards, it also works on template arguments.
Andreas Dolk
thanks for clarification. I was really unsure, my first intention was that it
<T extends Something> is correct but I was quite irritated after reading this one chapter of the language spec.