‘변경 불가능한 뷰’의 명백한 단점은 기존 컬렉션에 대한 추상화에 불과하다는 것입니다. 다
음 코드는 기본 컬렉션이 여전히 변경될 수 있으며, 이 변경이 ‘변경 불가능한 뷰’에 어떤 영
향을 미치는지를 보여줍니다.
List
<
String
>
original
=
new ArrayList
<>();
original
.
add
("
blue
");
original
.
add
("
red
");
List
<
String
>
unmodifiable
=
Collections
.
unmodifiableList
(
original
);
original
.
add
("
green
");
System
.
out
.
println
(
unmodifiable
.
size
());
//
출력:
//
3
[그림
4
-
2
]에서 볼 수 있듯이, 원본 참조를 통해 데이터를 여전히 수정할 수 있습니다. 데이
터 구조가 메모리에 저장되는 방식 때문이죠. 변경되지 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.