0

My question is related to lists combined with generics in Java.

I have something like this

class A{
}
class B extends A{
}

List<? extends A> list = new ArrayList<A>();
list.add(new A()); //COMPILE ERROR
list.add(new B()); //COMPILE ERROR

I do not understand why there is a compilation error even with the assignment new ArrayList<A>().

user2048767
  • 135
  • 10

0 Answers0