The following line of code is throwing a compile error related to Renderer::onScoreChange. The reported error is:
Type mismatch.
Required:(Int, Int) → Unit
Found: KFunction3<Renderer, @ParameterName Int, @ParameterName Int, Unit>
var score by EngineObserver<Int>(20, Renderer::onScoreChange)
I'm trying to pass a function reference to a custom Delegate extending from the ObservableProperty class but not sure why its not recognizing the passed member function as satisfying the requirements of the function argument. Thoughts from anyone?
class EngineObserver<T>(
initialValue: T,
val notify : (oldVal : T, newVal : T) -> Unit
) : ObservableProperty<T>(initialValue) {
override fun afterChange(property: KProperty<*>,
oldValue: T,
newValue: T) {
super.afterChange(property, oldValue, newValue)
notify(oldValue, newValue)
}
}
class Renderer {
fun onScoreChange(oldVal : Int, newVal : Int){
println("Score changed from $oldVal to $newVal")
}
}