extends means an inclusive upper bound.
What is this, the end of the discussion. It is impossible to say extends T , but not T From JLS ยง4.5.1 :
An argument of type T1 is said to contain another argument of type T2 written by T2 <= T1 if the set of types denoted by T2 is supposedly a subset of the set of types denoted by T1 with reflexive and transitive closure following rules (where <: denotes subtyping ( ยง4.10 ) ):
// snip
What is it. T contained in ? extends T ? extends T
In addition, even if you could tie it that way, in fact it didnโt make a big difference. Let me tell you what you could; this would be illegal:
public List<? exclusive-extends MyClass> list = new ArrayList<>(); list.add(new MyClass());
But this anonymous class will not:
public List<? exclusive-extends MyClass> list = new ArrayList<>(); list.add(new MyClass(){});
However, there may be a problem with your real problem.
It seems to me that the real problem is that you do not want anyone to put BaseAbstract instances in your generic type; you only need subclasses.
Well, doing that is easy enough to achieve; BaseAbstract cannot be created at all because it is an abstract class. As long as the parameterized type is an abstract class, you're fine.
If you have a real class, not an abstract class, you can simply put a dummy abstract class between them, for example.
class Foo { } abstract class AbstractFoo extends Foo { }
source share