Hey <@U0ANUS2BA> ... trying to figure out how to a...
# reflect
a
Hey @udalov ... trying to figure out how to access the companion object instance via reflection when the class is private and therefore fields of the class will throws illegal access exception, como:
java.lang.IllegalAccessException: Class kotlin.reflect.jvm.internal.KClassImpl$objectInstance_$1 can not access a member of class uy.klutter.binder.TestConstruction$TestConstructWithCompanionCallables with modifiers "public static final"
I tried:
Copy code
constructClass.companionObject?.let { companion ->
    val name = companion.simpleName
    val field = companion.java.enclosingClass.getDeclaredField(name)
    field.isAccessible = true
    constructClass.companionObjectInstance
}
and it blows up on the lazy get of the last line.