AdalPari
11/04/2020, 9:07 AMpublic interface ThreadExecutor {
void execute(Runnable runnable);
}
Which I can call from Kotlin this way:
threadExecutor.execute { //code }
But, If I convert the interface to Kotlin, then I get an error in those calls, saying that they expect a Runnable but the return is Unit.
interface ThreadExecutor {
fun execute(runnable: Runnable)
}
And I have to explicitly create the Runnable object.
threadExecutor.execute(Runnable { /* Code */ })
Would be great to understand why it happens, but also any idea on how to better solve it without having to create the Runnable in every call?thanksforallthefish
11/04/2020, 9:09 AMfun interface ThreadExecutor {
fun execute(runnable: Runnable)
}
the magic work is fun
😄Rob Elliot
11/04/2020, 9:28 AMThreadExecutor
from Java, hence continuing to take a Runnable
rather than a () -> Unit
?AdalPari
11/04/2020, 9:49 AMAdalPari
11/04/2020, 9:51 AMkralli
11/04/2020, 1:44 PMThreadExecutor
a functional interface does not change anything in this example, because the SAM conversion is required for Runnable
and not ThreadExecutor
. However upgrading to 1.4 will solve this issue, as it widens the capabilities of SAM conversions in general.thanksforallthefish
11/04/2020, 2:04 PMAdalPari
11/04/2020, 2:08 PM