samedi 28 novembre 2020

How to reselove ambiguity when when using reflection?

I'm trying to perform the following line in Kotlin:

var str: KFunction<String> = "some Word"::toUpperCase

But compiler says:

Overload resolution ambiguity. All these functions match. public inline fun String.toUpperCase(): String defined in kotlin.text public inline fun String.toUpperCase(locale: Locale): String defined in kotlin.text

I thought that writing KFunction should overcome the ambiguity since not writing nothing before the String in KFunction means that the KFunciton shouldn't get parameters and only return a String (which compatible with the function that is defined in kotlin.text package, but it seems that the compiler want some more info. I'm also trying the following assignment:

    var str: KFunction<java.util.Locale,String> = "some Word"::toUpperCase

And getting additional error saying that:

One type argument expected for interface KFunction

What Am I missing here?





Aucun commentaire:

Enregistrer un commentaire