Is there a methodology I can use to instantiate a ...
# announcements
t
Is there a methodology I can use to instantiate a random subclass of a common/abstract superclass (all subclasses inherit the same constructor)? Or do I need to hardcode a list/when structure of subclass references to draw from?
n
I think you can enumerate subclasses of a sealed class using Kotlin reflection, but more than that will require something more involved
u
If you don't want to use sealed classes like max mentioned, it's possible to use a library like classgraph to accomplish what you want. Sealed classes probably not a bad choice though especially since you can place them outside the same file now I think