I have an instance of `KProperty1<*,*>` such...
# getting-started
v
I have an instance of
KProperty1<*,*>
such as
MyPerson::age
. From this instance, how can I get
MyPerson::class
? Introspecting the object there is a
container
field that contains the value I want but there does not seem to be any API to access it officially. think smart
Copy code
fun KProperty<*>.declaringClass(): Class<*> {
    return (this.javaField as Member? ?: this.javaGetter)?.declaringClass
             ?: error("Unable to access declaring class")
}
s
Maybe you want this?
Copy code
myPropertyReference.instanceParameter?.type?.classifier
v
that is indeed exactly what I want, thanks Sam!
🐕 1