explaingit

ronmamo/reflections

4,771JavaAudience · developerComplexity · 2/5Setup · easy

TLDR

A Java library that scans your project's classes and builds a searchable index of metadata, so you can find every class, method, or annotation matching a condition with a single line of code instead of writing lots of boilerplate.

Mindmap

mindmap
  root((repo))
    Scanning
      Package scanning
      Metadata indexing
      Configurable filters
    Querying
      Subtype lookup
      Annotation search
      Interface finder
    Results
      Class objects
      Method objects
      Field objects
    Use Cases
      Plugin systems
      Dependency injection
      Dynamic loading
    Setup
      Maven dependency
      Gradle dependency
    Status
      Version 0.10.2
      Not maintained
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Find every class that extends a base class or implements an interface without manually scanning files.

USE CASE 2

Build plugin systems that automatically discover and load components present in the project.

USE CASE 3

Support dependency injection frameworks that wire together components without explicit config files.

USE CASE 4

Create testing tools that locate all classes or methods tagged with a specific annotation.

Tech stack

JavaMavenGradle

Getting it running

Difficulty · easy Time to first run · 30min

Add a single Maven or Gradle dependency for version 0.10.2. Note: the project is no longer actively maintained, so no new releases or bug fixes should be expected.

Not mentioned in the explanation.

In plain English

Reflections is a Java library that lets a program ask questions about its own code at runtime. In Java, every class, method, and annotation is described by metadata that the language keeps around while a program is running. Normally accessing this information requires writing a lot of boilerplate code. Reflections scans all the classes in a project and builds a searchable index of that metadata, so developers can look things up with simple queries instead. For example, a developer might want to find every class that extends a particular base class, every method tagged with a certain annotation, or every class that implements a specific interface. Without a library like Reflections, this requires walking through every file manually. With it, a single line of code returns the set of matching items. This is useful for building plugin systems, dependency injection frameworks, testing tools, and any code that needs to discover and load components dynamically based on what is present in the project. The library is configured by telling it which packages to scan and which types of metadata to index. You can choose to index only subtype relationships, only annotated types, only annotated methods, or all of the above. Once the scan is done, the index is queried using a fluent API where you chain together conditions to describe what you want. Results can be returned as Class objects, Method objects, Field objects, or strings depending on what you asked for. Reflections is added to a Java project through Maven or Gradle with a single dependency line. The last stable release was version 0.10.2 in October 2021. The README notes clearly that the project is not currently under active development or maintenance, though the code remains available and prior releases continue to work. The library is widely used in the Java ecosystem, particularly by frameworks and tools that need to discover and wire together components without requiring developers to list them explicitly in a configuration file.

Copy-paste prompts

Prompt 1
Using the Reflections library, write Java code to find all classes in the com.example package that implement the Plugin interface and print their names.
Prompt 2
Show me how to configure Reflections to scan only annotated methods and return every method tagged with @Scheduled in my Spring project.
Prompt 3
I want to build a simple plugin loader using Reflections 0.10.2. Write the setup code that scans a package, finds all subclasses of BasePlugin, and instantiates each one.
Prompt 4
How do I add Reflections to my Gradle project and write a one-liner query to get all types annotated with @Component?
Prompt 5
Explain the difference between indexing SubTypesScanner and TypeAnnotationsScanner in Reflections, and show a code example of querying each.
Open on GitHub → Explain another repo

← ronmamo on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.