What is the difference between google's ImmutableList and Collections.unmodifiableList ()?

后端 未结 5 1251
孤城傲影
孤城傲影 2020-12-08 02:11

From ImmutableList javadocs:

Unlike Collections.unmodifiableList(java.util.List), which is a view of a separate collection that can still change

5条回答
  •  时光说笑
    2020-12-08 02:43

    1. No, the contained individual objects can still be modified. A collection is really only storing references to the contained objects, not a full copy of every object.
    2. You can modify the list by modifying the parent Collection you called Collections.unmodifiableList(list) on. But yes, you CAN use setDimension to change a stored list element.

提交回复
热议问题