jeudi 25 juin 2020

Access inner class Parent KType reflectivly in kotlin

I'm trying to instantiate an inner class reflectively using Kotlin-reflection library it's not hard except that I need to pass an instance of the parent class to the child class constructor.

Is there any function/way to get the KType of the parent class (without using it's name and Class.forName())?

here is an example of what I'm trying to achieve:

class Parent {
    inner class Child()
}
fun main() {
    val childType: KType = typeOf<Parent.Child>()
    val parentType = childType.getParent()
}




Aucun commentaire:

Enregistrer un commentaire