Java using generics with lists and interfaces
- by MirroredFate
Ok, so here is my problem:
I have a list containing interfaces - List<Interface> a - and a list of interfaces that extend that interface: List<SubInterface> b. I want to set a = b. I do not wish to use addAll() or anything that will cost more memory as what I am doing is already very cost-intensive. I literally need to be able to say a = b. I have tried List<? extends Interface> a, but then I cannot add Interfaces to the list a, only the SubInterfaces. Any suggestions?
EDIT
I want to be able to do something like this:
List<SubRecord> records = new ArrayList<SubRecord>();
//add things to records
recordKeeper.myList = records;
The class RecordKeeper is the one that contains the list of Interfaces (NOT subInterfaces)
public class RecordKeeper{
public List<Record> myList;
}