XUtils

Reflections

Reflections scans your classpath, indexes the metadata, allows you to query it on runtime and may save and collect that information for many modules within your project.


Maven

<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>

Gradle

implementation ‘org.reflections:reflections:0.10.2’


Create Reflections instance and use the query functions: 
```java
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());

Or using previous 0.9.x APIs, for example:

Set<Class<? extends SomeType>> subTypes =
  reflections.getSubTypesOf(SomeType.class);

Set<Class<?>> annotated = 
  reflections.getTypesAnnotatedWith(SomeAnnotation.class);

Note that there are some breaking changes with Reflections 0.10+, along with performance improvements and more functional API, see below.


Articles

  • coming soon...