In Java it works by accepting an object which implements runnable :
Thread myThread = new Thread(new myRunnable())
where myRunnable
is a class implementing Runnable
.
But when I tried this in Kotlin, it doesn't seems to work:
var myThread:Thread = myRunnable:Runnable
Runnable:
Thread:
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:
I did the following and it appears to be working as expected.