https://kotlinlang.org logo
#reflect
Title
# reflect
d

diesieben07

08/25/2018, 1:39 PM
When obtaining a
KFunction
via a function reference, how do you resolve an "overload resolution ambiguity"? I am trying to get a
KFunction<String>
for
ResultSet::getString
, but there are two versions of that (
getString(Int)
and
getString(String)
). How do I tell the compiler I want the
Int
version?
u

udalov

08/27/2018, 1:16 PM
Provide an expected type in some form, for example:
Copy code
class A {
    fun getResult(s: String) {}
    fun getResult(i: Int) {}
}

val a: (A, String) -> Unit = A::getResult
d

diesieben07

08/27/2018, 1:20 PM
Yes, but then I have
(A, String) -> Unit
, which is not assignable to
KFunction
.
u

udalov

08/31/2018, 1:04 PM
Right. You can also do
Copy code
val a: kotlin.reflect.KFunction2<A, String, Unit> = A::getResult
👍 1
KFunction2
is a synthetic type which extends from
KFunction
and `Function2`; erased to
KFunction
on JVM
d

diesieben07

08/31/2018, 1:06 PM
Thank you very much!
23 Views