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.
You could define your Base
class as sealed class Base
and then access Base::class.sealedSubclasses
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.