好的,所以这是我的问题:
我有一个包含接口的列表List<Interface> a- 以及扩展该接口的接口列表:List<SubInterface> b.我想设置a = b.我不想使用addAll()或任何会花费更多内存的东西,因为我正在做的事情已经非常耗费成本.我真的需要能够说出来a = b.我试过List<? extends Interface> a,但后来我不能将接口添加到列表中a,只能添加SubInterfaces.有什么建议?
编辑
我希望能够做到这样的事情:
List<SubRecord> records = new ArrayList<SubRecord>();
//add things to records
recordKeeper.myList = records;
Run Code Online (Sandbox Code Playgroud)
RecordKeeper类是包含接口列表(NOT子接口)的类
public class RecordKeeper{
public List<Record> myList;
}
Run Code Online (Sandbox Code Playgroud)
另一个编辑:
我发布了我的工作解决方案.我感谢所有回答的人,并为显然让我的问题如此混乱而道歉.