How to assign a java method with overload to a variable

// None of the following functions can be called with the arguments supplied.
val log: (String, String, Throwable) -> Unit = Log::e

// Unexpected token
val log: (String!, String!, Throwable!) -> Unit = Log::e

// Overload resolution ambiguity. All these functions match.
val log = Log::e

Is that a way to assign overload java method to a variable?

The error message shown by Kotlin is misleading in this case. The first declaration is not accepted because Log.e returns Int, not Unit. The following declaration works correctly:

val log: (String, String, Throwable) -> Int = Log::e
1 Like

I feel stupid now. I have never noticed Log.e has a return value