Say I have a data class:
data class Money(private var _amount: Int, private val currency: String) {
private var amount: Int = _amount
get() {
return if (field < 0) 0 else field
}
override fun toString(): String {
return "Money(amount=$amount, currency='$currency')"
}
}
I want to know what should I pass as a parameter: var or val? Should I add private modification? In which case is the best practice? Because when I add a getter I must change it to var, but as I know, it's always better to write val in Kotlin?