Imagine that you have two subclasses:
class A1 implements A {...}
class A2 implements A {...}
Then you could write:
List<? extends A> elements = new ArrayList<A1>(); // a list of A1
But then this should not compile:
elements.add(new A2()); //oops: an A2 is not an A1
For that reason, you can't add anything but null
to a List<? extends A>
because you don't know what actual generic type it is. In other words, ? extends A
means a specific, but unknown, subtype of A
(or A
itself).
In your case, a List<A>
would probably do what you expect - you would be able to add some A1
s and some A2
s to it.