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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -