If I write
List<Integer> a1 = Arrays.asList(1, 2, 3);
List<Integer> a2 = Collections.unmodifiableList(a1);
a2
is read-only but if I write
a1.set(0,10);
then a2
is also modified.
If in the API is said:
Returns an unmodifiable view of the specified collection. This method allows modules to provide users with "read-only" access to internal collections.
then, why if I modify the original collection also the target-copied collection is modified?
Maybe did I misunderstand the meaning and if so what's the way to write a defensive copy of that collection?