// User.kt
import kotlin.properties.Delegates
class User {
var name: String by Delegates.observable("<no name>") {
prop, old, new ->
println("$old -> $new")
}
}
fun main() {
val user = User()
user.name = "first"
user.name = "second"
}
// # output:
// <no name> -> first
// first -> second
Docs: Observable properties
Source: 7 Features in Kotlin's Standard Library that You Might Have Overlooked