In Java it works by accepting an object which implements runnable :
Thread myThread = new Thread(new myRunnable())
where myRunnable
Runnable:
val myRunnable = runnable {
}
Thread:
Thread({
// call runnable here
println("running from lambda: ${Thread.currentThread()}")
}).start()
You don't see a Runnable here: in Kotlin it can easily be replaced with a lambda expression. Is there a better way? Sure! Here's how you can instantiate and start a thread Kotlin-style:
thread(start = true) {
println("running from thread(): ${Thread.currentThread()}")
}