Kotlin prohibits the use of a variable or property inside its own initializer.
You can use the expression for implementation the Runnablesame way as in Java:
val cycleRunnable = object : Runnable {
override fun run() {
handler.postDelayed(this, 100)
}
}
Another way to do this is to use some function that will return Runnableand use cycleRunnableinside the lambda passed to it, for example:
val cycleRunnable: Runnable = run {
Runnable {
println(cycleRunnable)
}
}
. , :
: utils kotlin-fun :
val cycleRunnable: Runnable = selfReference {
Runnable {
handler.postDelayed(self, 100)
}
}