0

I have a class like this:

public class ClassList {

    public class SubClassOne {

    }

    public class SubClassTwo {

    }

}

Now i want to have a list of all classes in my ClassList class without having to add them all by hand. Is that possible?

DraxCode
  • 43
  • 5

1 Answers1

0

Returns an array containing Class objects representing all the public classes and interfaces that are members of the class represented by this Class object. ONLY public modifier

Returns an array of Class objects reflecting all the classes and interfaces declared as members of the class represented by this Class object. All (public, protected, default (package), private) modifiers


Class<ClassList> classList = ClassList.class;
Class<?>[] classes = classList.getClasses();
for (Class<?> c : classes) {
    System.out.println(c.getName());
}

packageName.ClassList$SubClassTwo
packageName.ClassList$SubClassOne
azro
  • 53,056
  • 7
  • 34
  • 70