If I have this java class
public class JavaClass {
public void withAction(Runnable action) {
}
}
Then I can call it from Kotlin like this:
JavaClass().withAction { println(“Hello”) }
But when I have this kotlin class:
class KotlinClass {
fun withAction(action: Runnable) {}
}
Then I have to call the method like this:
KotlinClass().withAction(Runnable { println(“Hello”) })
I can not call it like:
KotlinClass().withAction { println(“Hello”) }
Why is that? Why do I have to say its a Runnable when calling kotlin code but not when calling java code?
Please note that I do not want to change my kotlin class