1

I have a class called MyClass. Is it possible to programmatically find a list of classes that have inherited MyClass? I know we can use reflection to discover all the superclasses of a given class, but can we find the subclasses?

Is it even theoretically possible to do so (as I haven't heard of a class being aware of when it is being extended) ?

Shailesh Tainwala
  • 6,299
  • 12
  • 58
  • 69
  • 1
    http://stackoverflow.com/questions/492184/how-do-you-find-all-subclasses-of-a-given-class-in-java – Adisesha Apr 27 '11 at 11:03

1 Answers1

6

You might want to look at the reflections library


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
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130