任何人都知道 List 复制 impl 仅在突变时才实际制作副本?对于以读取为主的用例,它(编辑:可能)比new ArrayList<>(oldList)
. 就像CopyOnWriteArrayList
它只会复制元素零次或一次。
例子:
List list = Lists.lazyCopy(oldList); // no copy
list.get(0); // delegate to oldList
list.set(0, null); // make a copy, mutate the copy
list.get(0); // read from copy
list.set(0, null); // mutate the copy, don't copy again