java list all the child classes of a parent

inheritance, java, reflection

Solution

I would use http://code.google.com/p/reflections/

Using Reflections you can query your metadata such as:

- get all subtypes of some type

- get all types/methods/fields annotated with some annotation, w/o annotation parameters matching

- get all resources matching matching a regular expression

This can be used in an indexed or cached mode. As @Jagger suggests, a brute force search of every class is relatively slow. You can also limit the search by package e.g. `com.mycom.*`

Problem

Possible Duplicate: At runtime, find all classes in a Java application that extend a base class I need to get list of all the classes (child) which extends a particular class (parent) and then create an instance of them all. how should I do this in Java?

Original source

Related problems