0

In the following (simplified) code, the compiler shouts at the add method (cannot be applied), as explained well in Jon Skeet's answer. Is there a clean way to assign my extended class onto the generic array?

class a {}
class b extends a {}

ArrayList<? extends a> arr;

void f() {
    arr.add(new b());
}
Community
  • 1
  • 1
jazzgil
  • 2,170
  • 2
  • 17
  • 20

1 Answers1

0

a1 type should be ArrayList<? extends a> a1;

Rahman
  • 3,645
  • 3
  • 22
  • 34