This thing has me stumped. I have a class as follows:
public class SpecialList implements List<MyType> {
// overriden methods
}
Now I have the following method contract to respect in a higher class:
public class MyClass {
private List<SpecialList> bigList = new ArrayList<SpecialList>();
public void doStuff(List<MyType> list)
{
bigList.add((SpecialList)list); // does not compile - invalid cast
}
}
I really am not sure what I am doing wrong here. I have a class that implements the List<MyType> interface, yet I can't cast that class to a List<MyType>? That doesn't make any sense to me.
I am lost. What am I supposed to do to make this work? I suppose this has something to do with generics covariance but at this point I don't know what is wrong here. Can someone point in the right direction? Thanks.
listtobigListor addlisttobigListbigList.addAll(list);addAllisn't appropriate here I think.