In pseudocode I’ve got:
abstract class Event
{
...
public static class MouseEvent extends Event
{
...
}
public static class KeyboardEvent extends Event
{
...
}
public static class NetworkEvent extends Event
{
...
}
}
Is there a neat way to get a collection of the names/details of all the inner-class subclasses? Preferably as a method on the base Event class…
I believe that you want
Event.class.getDeclaredClasses().Will give you the expected output:
However, I think that you are looking for a more open scanning mechanism which does not limit itself to inner classes. Based on this question, it does not look like there is a straight-forward way to do this.
The Spring framework does something like this with its annotation scanning (see
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider), but their approach is not a straight-forward method call.