DasBrain / bean-mirror

Modern reflection library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bean Mirror

Apache 2 License Build Status Coverage Status Maven Central JavaDoc

Bean Mirror is a fluent, type-safe reflection library for the latest Java versions.

Features

  • Fluent API
  • Type-safe
  • Modularized
  • Lightweight, no dependencies

Requirements

  • Java 11+

Motivation

There are several reflection based libraries which allow the developers to easily manipulate objects during runtime. What separates this library is that it uses the newer API (java.lang.invoke) which allows faster code if used properly, compared to the classic java.lang.reflect package.

Because several additions have been added in Java 9 setting the minimum required Java version to anything lower is not feasible (it would not make sense to create another library, which would not be any different from the existing ones).

The project was inspired by jOOR. If you are using an older Java I suggest using that instead.

Examples

        // Get the name of the school principal by field access
        final String principalName = BeanMirror.of(school, MethodHandles.lookup())
                .field("principal", Principal.class)
                .get("name", String.class);
        // Create a setter function to set the value on any instance
        final BiConsumer<Student, Integer> setter = BeanMirror.of(Student.class, MethodHandles.lookup())
                .createSetter("startingYear", Integer.class);

        setter.accept(student, 2018);
        setter.accept(otherStudent, 2020);

Documentation

Javadoc

Gradle

compile 'com.github.elopteryx:bean-mirror:1.1.0'

Maven

<dependency>
    <groupId>com.github.elopteryx</groupId>
    <artifactId>bean-mirror</artifactId>
    <version>1.1.0</version>
</dependency>

Find available versions on Maven Central Repository.

About

Modern reflection library.


Languages

Language:Java 100.0%