Hi all. Is there a specific reason why the initial...
# getting-started
d
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
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
there are already enough ways to violate nullability constraints during initialization in Kotlin, we don't need more
d
Makes sense. Thank you 🙂