Skip to Content
함수형 프로그래밍 with 자바
book

함수형 프로그래밍 with 자바

by 벤 바이디히, 허귀영
March 2024
Beginner to intermediate
528 pages
10h 48m
Korean
Hanbit Media, Inc.
Content preview from 함수형 프로그래밍 with 자바
119
CHAPTER 04
불변성
List
<
String
>
modifiable
=
new ArrayList
<>();
modifiable
.
add
("
blue
");
modifiable
.
add
("
red
");
List
<
String
>
unmodifiable
=
Collections
.
unmodifiableList
(
modifiable
);
unmodifiable
.
clear
();
//
UnsupportedOperationException
발생
‘변경 불가능한 뷰’의 명백한 단점은 기존 컬렉션에 대한 추상화에 불과하다는 것입니다. 다
음 코드는 기본 컬렉션이 여전히 변경될 수 있으며, 이 변경이 ‘변경 불가능한 뷰’에 어떤 영
향을 미치는지를 보여줍니다.
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.
Start your free trial

You might also like

실무로 통하는 클린 코드

실무로 통하는 클린 코드

막시밀리아노 콘티에리

Publisher Resources

ISBN: 9791169212175