In Kotlin we can define an observable for a non-null property,
var name: String by Delegates.observable("<no name>") {
prop, old, new ->
println("$old -> $new")
}
however this is not possible
var name: String? by Delegates.observable("<no name>") {
prop, old, new ->
println("$old -> $new")
}
What would be the way to define an observable for a nullable property?
编辑:这是编译错误
Property delegate must have a 'setValue(DataEntryRepositoryImpl, KProperty<*>, String?)' method. None of the following functions is suitable:
public abstract operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String): Unit defined in kotlin.properties.ReadWriteProperty