6

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?

4

1 に答える 1

6

ここでの曖昧さ回避は現在サポートされていません (後でサポートされる予定です)。

回避策として、ラムダ式を使用できます。

{ s, s1 -> android.util.Log.d(s, s1) }
于 2014-12-08T11:34:23.067 に答える