我有代码(完整源代码):
public class AutoConversionTest {
@Test
public void test_autoConversion() {
Wrapper wrapper = new Wrapper();
wrapper.setList(new ArrayList<Sub>());
wrapper.addAll(new ArrayList<Sub>());
}
class Wrapper {
List<? extends Super> list;
public void setList(List<? extends Super> list) {
this.list = list;
}
public void addAll(List<? extends Super> list) {
this.list.addAll(list); //TROUBLES!
}
}
class Super {}
class Sub extends Super {}
}
问题:Wy 错误以及如何解决?
编辑:我的错误日志
java: no suitable method found for `addAll(java.util.List<? extends expectations.public_method.experiments.AutoConversionTest.Super>)`
method `java.util.List.addAll(int,java.util.Collection<? extends expectations.public_method.experiments.AutoConversionTest.Super>)` is not applicable (actual and formal argument lists differ in length)
method `java.util.List.addAll(java.util.Collection<? extends expectations.public_method.experiments.AutoConversionTest.Super>)` is not applicable (actual argument `java.util.List<? extends expectations.public_method.experiments.AutoConversionTest.Super>` cannot be converted to `java.util.Collection<? extends expectations.public_method.experiments.AutoConversionTest.Super>` by method invocation conversion)