private fun bearable(routes: List<List<Journey>>): List<List<Journey>> =
routes.filter { sufferScoreFor(it) <= 10 }
흥미롭게도 이 코드는 원래의 자바 코드보다 변환한 코틀린 코드가 더 가변적인 경우이다. 자
바에서는
Collectors
.
toUnmodifiableList
()
를 사용해 데이터를 수집하지만, 코틀린
filter
는 반환 타입을
List
(읽기 전용 뷰)로 선언한다. 하지만 실제 반환 값의 실행 시점 타
입은 가변
ArrayList
이다. 다운캐스트를 결코 하지
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.