Lateinit property before it has been initialized
Fri, May 13, 2016The follwing exceptions and are using the lateinit occurred.
class UdonMaker {
lateinit var callback:Callback
fun onCreate(callback: Callback) {
this.callback = callback
...
}
fun onResult(result:Result) {
if (result.code == "OK") {
callback.onSucess() // lateinit property before it has been initialized
} else {
callback.onFail()
}
}
interface callback {
onSuccess()
onFail()
}
}
fun onCreate() {
UdonMaker().onCreate(object : Callback {
override fun onSucess() {}
override fun onFail() {}
})
}
Accessing a lateinit property before it has been initialized throws a special exception that clearly identifies the property being accessed and the fact that it hasn’t been initialized
var callback:Callback? = null