Skip to Content
자바에서 코틀린으로
book

자바에서 코틀린으로

by 덩컨 맥그레거, 냇 프라이스, 오현석
November 2022
Beginner to intermediate
544 pages
12h 39m
Korean
Hanbit Media, Inc.
Content preview from 자바에서 코틀린으로
225
11
메서드에서 프로퍼티로
예제
11.10
[
methods
-
to
-
properties
.
7
:
src
/
main
/
java
/
travelator
/
CampSites
.
kt
]
fun Iterable<CampSite>.sitesInRegion(
countryISO: String,
region: String
): Set<CampSite> =
filter { site ->
site.isIn(countryISO, region)
}.toSet()
fun CampSite.isIn(countryISO: String, region: String) =
countryCode == countryISO &&
this.region.equals(region, ignoreCase = true)
Campsite
.
isIn
(...)
이 있으므로 이제
sitesInRegion
을 함수를 호출한 위치에 인라이닝
할 수 있을 것이다. 이제는 코드가 스스로 자신이 하는 일을 잘 설명해 주기 때문이다. 우리는
클라이언트를 구축할 수 있는 기초 연산을 함수 안에 감추기보다는 찾아서 공개하는 쪽을 선호
한다. 이런 방향을 따르면
region
을 선택적인 인자로 정의함으로써
isIn
의 기능을 확장할 수
있다.
예제
11.11
[
methods
-
to
-
properties
.
8
:
src
/
main
/
java
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

고성능 파이썬(2판)

고성능 파이썬(2판)

오현석, 미샤 고렐릭, 이안 오스발트
러닝 타입스크립트

러닝 타입스크립트

조시 골드버그
실리콘밸리 리더십

실리콘밸리 리더십

김정혜, 마이클 롭

Publisher Resources

ISBN: 9791169210447