我有以下的Java代码:
List<SomePojo> list = new ArrayList<SomePojo>();
//add 100 SomePojo objects to list.
现在列表有100个对象。
如果我按照以下方式创建一个新实例:
List<SomePojo> anotherList = new ArrayList<SomePojo>();
anotherList.addAll(list);
现在,内存中会有多少个对象:100个还是200个对象?
在下面的行中,是添加了对象还是只添加了引用?
anotherList.addAll(list);
如果我对 list
进行任何更改,这些更改会反映到 anotherList
上吗?反之亦然?