[英]How to programmatically find list of classes that have inherited a particular class in Java
I have a class called MyClass.我有一个名为 MyClass 的 class。 Is it possible to programmatically find a list of classes that have inherited MyClass?
是否可以以编程方式查找继承了 MyClass 的类的列表? I know we can use reflection to discover all the superclasses of a given class, but can we find the subclasses?
我知道我们可以使用反射来发现给定 class 的所有超类,但是我们能找到子类吗?
Is it even theoretically possible to do so (as I haven't heard of a class being aware of when it is being extended)?理论上是否有可能这样做(因为我还没有听说过 class 知道它何时被扩展)?
You might want to look at the reflections library您可能想查看反射库
Using Reflections you can query your metadata such as:使用反射,您可以查询元数据,例如:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.