August 2017
Intermediate to advanced
440 pages
10h
English
The observable is the most useful standard library delegate for mutable properties. Every time a value is set (the setValue method is called), the lambda function from the declaration is invoked. A simple example of the observable delegate is as follows:
var name: String by Delegates.observable("Empty"){
property, oldValue, newValue -> // 1
println("$oldValue -> $newValue") // 2
}
// Usage
name = "Martin" // 3 Prints: Empty -> Martin
name = "Igor" // 3 Prints: Martin -> Igor
name = "Igor" // 3, 4 Prints: Igor -> Igor
Read now
Unlock full access