这是我的简化代码,因为classA.onChange始终为null,因此从不显示烤面包。
class A {
var propertyToObserve:Long by observable(0L) { _, oldValue, newValue ->
onChange?.invoke(oldValue, newValue)
}
var onChange: ((Long, Long) -> Unit)? = null
}
class B {
var classA = A()
classA.onChange = {
Toast.makeText(this, "Property changed", Toast.LENGTH_SHORT).show()
}
A.propertyToObserve = 15L
}