开发者

How to programmatically find list of classes that have inherited a particular class in Java

开发者 https://www.devze.com 2023-03-01 04:24 出处:网络
I have a class called MyClass. Is it possible to programmatically find a list of classes that have inherited MyClass?

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 be开发者_如何学运维ing extended) ?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消