Type mismatch when passing functional interface argument


If I have this method signature in Java:

void execute(Handler<AsyncResult<Void>> callback) { ... }

In Kotlin I can just call the function and pass the argument with this code:

execute { ... }

But, if I create the function with the same signature in Kotlin:

fun execute(callback: Handler<AsyncResult<Unit>>) { ... }

I can't call the function with same code above, Kotlin won't compile and said this:

Type mismatch. Required: Handler<AsyncResult<Unit>> Found: () -> Unit ( or to be worse: (???) -> (???) )

Unless if I code like this then it won't be a problem:

execute( Handler { ... } )

Just fyi, Handler is a functional interface (an interface with @FunctionalInterface annotation).


I complained about something similar, see Andrey's answer here:



Thanks for pointing me to the link.