Why doesn't this work? I thought the list would be able to accept any object that is an instance of A
.
import java.util.List;
public class Test {
interface A {}
interface B extends A {}
class BImpl implements B {}
List<? extends A> listOfAExtensions;
void function() {
B b = new BImpl();
listOfAExtensions.add(b);
// error
// The method add(capture#1-of ? extends Test.A)
// in the type List<capture#1-of ? extends Test.A>
// is not applicable for the arguments (Test.B)
}
}