【发布时间】:2018-03-06 08:49:11
【问题描述】:
为什么这不起作用?我认为该列表将能够接受任何作为 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)
}
}
【问题讨论】: