Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve overload ambiguity in method references?

Say I want to assign the java method Log.d(String, String) to a variable x of method type (String, String) -> Int and I do it like this:

val x: (String, String) -> Int = android.util.Log::d

The compiler says:

Error:(50, 56) Overload resolution ambiguity:
public open fun d(tag: kotlin.String!, msg: kotlin.String!): kotlin.Int defined in android.util.Log
public open fun d(tag: kotlin.String!, msg: kotlin.String!, tr: kotlin.Throwable!): kotlin.Int defined in android.util.Log

Obviously there is a second method Log.d(String, String, Throwable) but how do I tell the compiler which one I want?

like image 360
Kirill Rakhman Avatar asked Dec 08 '14 09:12

Kirill Rakhman


1 Answers

Disambiguation here is currently unsupported (will be supported later).

As a workaround, you can use a lambda expression:

{ s, s1 -> android.util.Log.d(s, s1) }
like image 62
Andrey Breslav Avatar answered Jan 03 '23 23:01

Andrey Breslav