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.