I have a method reference (represented by the kotlin.reflect.KFunction0
interface). What I would like to do is to get the receiver
object of the method reference.
For example:
data class MyClass(val name: String)
val john = MyClass("John")
val methodReference = john::toString
methodReference.receiver // doesn't work!
The receiver
of methodReference
is the object john
. If I look into the IntelliJ debugger, methodReference
has a receiver
field which indeed points to john
. But I cannot find a way to actually access it in my code.
Is there some sort of workaround for this?