我被一个我不明白的愚蠢问题困住了。
class Foo<T extends Collection<E>, E> {
private Class<T> collectionClass;
private Class<E> elementClass;
public Foo(Class<T> collectionClass, Class<E> elementClass) {
this.collectionClass = collectionClass;
this.elementClass = elementClass;
}
}
当我尝试运行它时
Foo<Collection<String>, String> foo =
new Foo<Collection<String>, String>(
Collection.class,
String.class);
我收到编译器错误
java.lang.Error: Unresolved compilation problem:
The constructor Foo<Collection<String>,String>(Class<Collection>, Class<String>) is undefined
为什么 ?如果我删除泛型,没关系
Foo foo =
new Foo(
Collection.class,
String.class);
如果有人有一个想法,那就太好了,阻止我把头撞到墙上。