我收到此錯誤與下面的代碼:使用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