下面的代码对我来说完全有意义 - 关于添加一个类型为T和S的超类型的元素肯定是这样的一个超类型,那么为什么编译器拒绝将'元素'添加到集合中呢?无法编译的有界通用方法 - 为什么?
class GenericType<S,T extends S>{
void add1(Collection<? super T> col ,S element){
col.add(element); // error
// The method add(capture#9-of ? super T) in the type
// Collection<capture#9-of ? super T> is not applicable for the arguments (S)
}
}
给你说什么,怎么那么该声明从东西做*不*使用通配符(收藏而不是收集 super T>)有什么不同? –
Bhaskar
2011-06-07 12:07:49
@Bhaskar:通配符还允许您使用Collection
或Collection