reflection - How to access the object-members of an object declaration in kotlin -
say have following, nested object declaration:
object father { val fathersfield = "value" object child { val childsfield = 3.141592654 } }
when use reflection starting father
, i'm able find field fathersfield
no member referencing child
instance.
is possible find inner object declarations via reflection? , if so, how?
use nestedclasses
kotlin-reflect
:
father::class.nestedclasses.find { it.simplename == "child" }
or, @s1m0nw1 suggested, use java reflection , convert class
kclass
.kotlin
if needed:
father::class.java.classes.first { it.simplename == "child" }.kotlin
Comments
Post a Comment