Can you specify super
and extends
for generics in Java?
For example, let's say you have this class structure:
But only want to select classes that: extends A
and super ABB
. Is that possible?
Can you specify super
and extends
for generics in Java?
For example, let's say you have this class structure:
But only want to select classes that: extends A
and super ABB
. Is that possible?
No, Java does not let you simultaneously specify both bounds. That said, I've never run across a situation where both bounds were needed. There's almost no reason to include some subclasses but not others - if you need to exclude subclasses, those subclasses are probably violating their contract.