Playing with Reflection API and property reference I tried something like this :
data class Point(val x:Int, val y:Int)
val p = Point(5,13)
val getter1 = Point::x
val getter2: (Point) -> Int = Point::x
println(getter1(p)) // 5
println(getter2(p)) // 5
What I don’t understand is why with
getter1 I was able to get reflection information about x for example I could do something like :
println(getter1.visibility) // PUBLIC
println(getter1.returnType) // <http://kotlin.Int|kotlin.Int>
while with getter2 I can’t, even if I use the
@OptIn(ExperimentalReflectionOnLambdas::class)
with
println(getter2.reflect()?.returnType)
the result is null.