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

자바에서 코틀린으로

by 덩컨 맥그레거, 냇 프라이스, 오현석
November 2022
Beginner to intermediate
544 pages
12h 39m
Korean
Hanbit Media, Inc.
Content preview from 자바에서 코틀린으로
283
14
누적시키는 객체에서 변환으로
이제
CostSummaryCalculator
.
summarise
메서드가 새 생성자를 호출하고,
CostSummary
클래스를 불변 값 타입처럼 다루도록 변경하자.
예제
14.12
[
accumulator
.
5
:
src
/
main
/
java
/
travelator
/
itinerary
/
CostSummaryCalculator
.
kt
]
fun summarise(): CostSummary {
val conversions = currencyTotals.values.sortedBy {
it.currency.currencyCode
}.map { exchangeRates.convert(it, userCurrency) }
return CostSummary(userCurrency, conversions)
}
이 변경의 결과,
CostSummary
클래스를 실제로(적어도 밖에서 볼 때는 ) 불변으로 보이게 할
수 있다.
예제
14.13
[
accumulator
.
6
:
src
/
main
/
java
/
travelator
/
itinerary
/
CostSummary
.
kt
]
class CostSummary(
userCurrency: Currency,
val lines: List<CurrencyConversion>
) {
var total: Money = ...
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