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

함수형 프로그래밍 with 자바

by 벤 바이디히, 허귀영
March 2024
Beginner to intermediate
528 pages
10h 48m
Korean
Hanbit Media, Inc.
Content preview from 함수형 프로그래밍 with 자바
178
PART 02
함수형 접근 방식
//
이전
방식
if
(
obj instanceof String
)
{
String str
=
(
String
)
obj
;
//
...
}
//
자바
16
+
if
(
obj instanceof String str
)
{
//
...
}
자바
17
과 자바
18
switch
표현식
22
에 대한 패턴 매칭을 미리보기 기능으로 도입했습니
다.
//
기존의
스위치
패턴
매칭이
없는
경우
String formatted
=
"
unknown
";
if
(
obj instanceof Integer i
)
{
formatted
=
String
.
format
("
int
%
d
",
i
);
}
else if
(
obj instanceof Long l
)
{
formatted
=
String
.
format
("
long
%
d
",
l
);
}
else if
(
obj instanceof String str
)
{
formatted
=
String
.
format
("
String
%
s
",
str
);
}
//
스위치
패턴
매칭을
적용한
경우
String formatted
=
switch
(
obj
)
{
case Integer i
->
String
.
format
("
int
%
d
",
i
);
case Long l
->
String
.
format
("
long
%
d
",
l
);
case String s
->
String
.
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