아무 멤버도 남지 않을 때까지 멤버를 확장 함수로 변환하는 과정을 계속 할 수 있다. 심지어
size
와
get
도 제거할 수 있다. 다만 남은 자바 클라이언트에서는 이들을 정적으로 임포트해
사용해야 한다.
예제
15.11
[
encapsulated
-
collections
.
5
:
src
/
main
/
java
/
travelator
/
UI
.
java
]
public void render(Route route) {
for (int i = 0; i < RouteKt.getSize(route); i++) {
var journey = RouteKt.get(route, i);
render(journey);
}
}
(
size
메서드를
size
확장 프로퍼티로 변환했기 때문에 자바에서는
getSize
함수를 사용한
다는 점을 기억하라.)
이제 한때는 꽉 들어차 있던
Route
클래스에 남은 것은 아래와 같이 리스트 하나뿐이다.
예제
15.12
[
encapsulated
-
collections
.
5
:
src
/
main
/
java
/
travelator
/
itinerary
/
Route
.
kt
]
class Route(
val journeys: List<Journey>
)
val Route.size: Int
get() = journeys.size ...
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.