Hi all. Is there a specific reason why the initial assigment of a property does not call its setter?
Copy code
var discount: Discount = discount.also { it.constraints = this }
set(value) {
field = value
field.constraints = this
}
Somehow I would like to avoid the duplicated code.
e
ephemient
11/24/2023, 3:56 AM
patterns like
Copy code
var x
set(value) {
if (value != field) notifyChange(field, value)
field = value
}
val changes = mutableListOf()
fun notifyChange(old, new) {
changes.add(old to new)
would be problematic as both
field
and the rest of the class are not yet initialized
ephemient
11/24/2023, 3:57 AM
there are already enough ways to violate nullability constraints during initialization in Kotlin, we don't need more