Smart casting of Kotlin functions to Java SAMs?


#1

Why does this work:

   Platform.runLater { ....code..... }

Given a Java prototype of:

   public static void runLater(Runnable runnable)

… but this does not work …

    val x: Runnable = { print("foo") }

Error: type mismatch: java.lang.Runnabel vs ()->Unit
If you write this though, the compiler is happy:

    val x: Runnable = Runnable { print("foo") }

Seems like the compiler should figure this out for itself.


#2

Looks like a bug to me. Could you please submit an issue?


#3

https://youtrack.jetbrains.com/issue/KT-8049