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,250
  • 2
  • 19
  • 20

1 Answers1

0

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

Rahman
  • 3,755
  • 3
  • 26
  • 43