Convert Java to Kotlin ERROR


when i convert my Java code to Kotlin,i got a error,any one can help? thanks~


I’d see if it’s any better if you change the first line to:

private val playTimeDelayRun: Runnable get() = Runnable {


If i define Runnable like this:

private val playTimeDelayRun: Runnable get() = Runnable {

Is not every call to get () will re-create a new Runnable return?


If it compiles then, yes, a new instance of Runnable will be created on each invocation.

However, if you’re converting from a Java ‘get’ accessor function, then that may be what would have happened anyway.

Also, there’s a danger that if the same instance were used in the recursive call then the code might be circular.


Maybe I should have this to define:

private lateinit var playTimeDelayRun: Runnable

playTimeDelayRun = Runnable{…}

But it’s not simple to write


Something like that might work but can you post your original Java code so I can try and work out what the closest Kotlin equivalent would be.