I am getting this error with the following code:
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 using Eclipse Helios with jdk 1.6.0_16.