Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7532049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:20:25+00:00 2026-05-30T05:20:25+00:00

In pseudocode I’ve got: abstract class Event { … public static class MouseEvent extends

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:20:27+00:00Added an answer on May 30, 2026 at 5:20 am

    I believe that you want Event.class.getDeclaredClasses().

    import java.util.ArrayList;
    import java.util.List;
    
    public class Event {
        public static class MouseEvent extends Event {}
        public static class KeyboardEvent extends Event {}
        public static class NetworkEvent extends Event {}
        public static class NotAnEvent {}
    
    public static List<Class<?>> getDeclaredEvents() {
            final Class<?>[] candidates = Event.class.getDeclaredClasses();
            final List<Class<?>> declaredEvents = new ArrayList<Class<?>>();
            for (final Class<?> candidate : candidates) {
                if (Event.class.isAssignableFrom(candidate)) {
                    declaredEvents.add(candidate);
                }
            }
            return declaredEvents;
        }
    
        public static void main(final String args[]) {
            final List<Class<?>> events = Event.getDeclaredEvents();
            for (final Class<?> event : events) {
                System.out.println("event class name: '" + event.getName() + "'.");
            }
        }
    }
    

    Will give you the expected output:

    event class name: 'Event$KeyboardEvent'.
    event class name: 'Event$MouseEvent'.
    event class name: 'Event$NetworkEvent'.
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this code (pseudocode) class SomeClass { class Person { public static
Example class in pseudocode: class SumCalculator method calculate(int1, int2) returns int What is a
Following pseudocode sums up my question pretty well I think... class Owner { Bar
I have the following class structure (pseudocode): Class A { Property string Who; Property
Assume we have following pseudocode: class XY { int X { get; set; }
If I have something like this (pseudocode): class A { List<SomeClass> list; private void
I have an object with the following structure: (pseudocode) class Client { - int
Imagine a hypothetical object with a number of attributes: pseudocode: class Student { Name:
As an example in pseudocode: if ((a mod 2) == 0) { isEven =
I'm looking for pseudocode, or sample code, to convert higher bit ascii characters (like,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.