Hi,
I have a class which functions as a collection where it has an add and remove of special items,
interface MyCollection<T extends Item>{
public void add(T t);
public void remove(T t);
}
This special collection will always have Items: These special items must have a reference to their specific collector of same type Items
interface Item{
public String getName();
public MyCollection<?> getCollection(); //the problem is here
Now, when I extend both classes, SpecialCollection will have SpecialItems:
public class SpecialCollection extends MyCollection<SpecialItem>{
}
//and
public class SpecialItem extends Item{
}
///to Test:
public static void main(String []a){
SpecialCollection sc=....
sc.add(new SpeicalItem());
SpecialItem si=sc.getItem();
MyCollection<SpecialItem> sc2=si.getCollection();//Error because I it will return MyCollection<?>
}
How can I slove this problem without a case?!
in other words, How can parametrize a method list this:
interface Item{
public MyCollection<T super THIS_CLASS WEATHER IT ITEM OR SUBTYPE CLASS> getCollection();
}
thank you!