Brian Carbone
11/13/2019, 3:55 PMget() = field.coerceAtLeast(0)
I don't know how to make a delegate to replace thisLuke
11/13/2019, 4:02 PMclass PositiveIntDelegate {
private var value = 0
operator fun getValue(thisRef: Any?, property: KProperty<*>) = value
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Int) {
this.value = value.coerceAtLeast(0)
}
}
Casey Brooks
11/13/2019, 4:03 PMReadWriteProperty
. So you can just create a delegate class with your custom coercion logic, and use that as the by
https://pl.kotl.in/JbGqyFAB7Casey Brooks
11/13/2019, 4:03 PMBrian Carbone
11/13/2019, 4:50 PMCasey Brooks
11/13/2019, 4:55 PMField
directly), then it should work fine, and it should go through your delegateBrian Carbone
11/13/2019, 4:57 PMBrian Carbone
11/13/2019, 4:57 PMCasey Brooks
11/13/2019, 5:00 PMBrian Carbone
11/13/2019, 5:02 PM