When obtaining a `KFunction` via a function refere...
# reflect
d
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
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
Yes, but then I have
(A, String) -> Unit
, which is not assignable to
KFunction
.
u
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
Thank you very much!