vendredi 1 juillet 2022

How to get a list of classes that extend from a base class in Kotlin?

consider following classes structure in Kotlin:

open class Base {
   ...
}

class A : Base() {
   ...
}

class B : Base() {
   ...
}

...

class Z : Base() {
   ...
}

How would I go around getting a list of ALL classes (A-Z in this particular example) that inherit from Base class?

I tried using reflection with BaseTest::class.nestedClasses and other reflection properties but they don't seem to be finding number of extending classes properly.





Aucun commentaire:

Enregistrer un commentaire