February 2018
Intermediate to advanced
350 pages
7h 35m
English
Delegates.vetoable is another standard delegate that allows us to veto a value change.
This right to veto allows us to have a logic check on each assignment of the property, where we can decide to continue with the assignment or not.
The following is an example:
var myIntEven:Int by Delegates.vetoable(0) {
property, oldValue, newValue ->
println("${property.name} $oldValue -> $newValue")
newValue%2==0
}
fun main(args: Array<String>) {
myIntEven = 6
myIntEven = 3
println("myIntEven:$myIntEven")
}
In this program, ...
Read now
Unlock full access