Java在运行期获取某个类的所有子类
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
Reflections reflections = new Reflections("com.my.project");
Set<Class<?>> subTypes =
reflections.get(SubTypes.of(SomeType.class).asClass());
Set<Class<?>> annotated =
reflections.get(SubTypes.of(TypesAnnotated.with(SomeAnnotation.class)).asClass());
文档:https://github.com/ronmamo/reflections
Loading...