我无法弄清楚以下代码有什么问题,具体来说,为什么不<A extends ClassA>
等同于<? extends ClassA>
.
应该不能bar()
打电话foo()
吧?
编译器说The method foo(...) is not applicable for the arguments (...)
(确切的错误在下面的评论中指定)
static class ClassA {};
static class ClassB<A extends ClassA> {};
private static <A extends ClassA> Collection<ClassB<A>> foo(Collection<ClassB<A>> as) {
return as;
}
private Collection<ClassB<? extends ClassA>> bar(Collection<ClassB<? extends ClassA>> as) {
// Error:
// The method foo(Collection<ClassB<A>>) is not applicable
// for the arguments (Collection<ClassB<? extends ClassA>>)
return foo(as);
}
谢谢!