Java在运行期获取某个类的所有子类

走着路睡觉
  • java
小于 1 分钟

<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

上次编辑于:
贡献者: zhaojingbo
Loading...