Java using generics with lists and interfaces

Posted by MirroredFate on Stack Overflow See other posts from Stack Overflow or by MirroredFate
Published on 2011-06-24T23:38:57Z Indexed on 2011/06/25 0:22 UTC
Read the original article Hit count: 122

Filed under:
|
|

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;
}

© Stack Overflow or respective owner

Related posts about java

Related posts about generics