I am running into issues trying to take a function as a parameter in a binding adapter using Kotlin/Android databinding. This example code throws e: error: cannot generate
Use function: Runnable
instead of function: () -> Unit
.
Android's data-binding compiler generates java code, to which, your kotlin function's signature looks like void testFunction()
, as kotlin adapts Unit as void when calling from java.
On the other hand, () -> Unit
looks like kotlin.jvm.functions.Function0
which is a function which takes 0 inputs and returns Unit.INSTANCE.
As you can see these two function signatures don't match, and that's why the compilation fails.