我收到此错误与下面的代码:使用Eclipse太阳神与JDK 1.6.0_16泛型示例不起作用?替代方案或建议?
The method getItemProperty(capture#2-of ? extends GenericTest.Item) in the type GenericTest.BaseContainer<capture#2-of ? extends GenericTest.Item> is not applicable for the arguments (GenericTest.Item)
import org.junit.Test;
public class GenericTest {
public class Item {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
public class WordItem extends Item {
}
public abstract class BaseContainer<T extends Item> {
public String getItemProperty(T item) {
return item.getValue();
}
}
public class Document extends BaseContainer<WordItem> {
}
public static class ContainerFactory {
public static BaseContainer<? extends Item> getContainer(Item item) {
return new GenericTest().new Document();
}
}
@Test
public void theTest(){
Item item = new WordItem();
BaseContainer<? extends Item> container = ContainerFactory.getContainer(item);
String str = container.getItemProperty(item); //this line does not compile
}
}
I'm。
什么是编译器给你的错误? – KLee1 2010-07-21 16:17:04
请在此问题中添加更多信息。或者它有被关闭的危险。 – jjnguy 2010-07-21 16:22:28
这是编译器错误 方法getItemProperty(捕获#2的?延伸GenericTest.Item)在GenericTest.BaseContainer <捕获#2的类型?扩展GenericTest.Item>是不适用的参数(GenericTest.Item)使用Eclipse赫利俄斯与JDK 1.6.0_16 – Alex 2010-07-21 16:25:38