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.
views:
99answers:
2... 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](http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.5.1) ...
Andreas_D
2010-07-20 08:13:11
+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.
Helper Method
2010-07-20 08:13:32
@Andreas: no, it doesn’t work only on wildcards, it also works on template arguments.
Konrad Rudolph
2010-07-20 11:04:24
@Konrad - 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.
Andreas_D
2010-07-20 11:14:19
A:
Have a look at http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf, 4.1 bounded wildcards
davyM
2010-07-20 08:11:02