Interface ReflectiveAccess


public interface ReflectiveAccess
This interface is used to register classes, methods, and fields for use with the java.lang.reflect API at run time, and for serialization at run time. An instance of this interface is acquired via Feature.AfterRegistrationAccess.getReflectiveAccess().

All methods in ReflectiveAccess require a AccessCondition as their first parameter. A class and its members will be accessible at run-time only if the specified condition is satisfied.

How to use

ReflectiveAccess should only be used during Feature.afterRegistration(Feature.AfterRegistrationAccess). Attempts to register metadata in any other phase of the Feature API will result in an error.

Example:

@Override
public void afterRegistration(AfterRegistrationAccess access) {
    ReflectionAccess reflection = access.getReflectionAccess();

    AccessCondition condition = AccessCondition.typeReached(ConditionType.class);
    reflection.register(condition, Foo.class, Bar.class);

    reflection.register(AccessCondition.unconditional(), Foo.class.getMethod("method"));

    reflection.registerForUnsafeAllocation(condition, Foo.class);

    Class<?> proxyClass = reflection.registerProxy(condition, Interface1.class, Interface2.class);
    reflection.registerForSerialization(AccessCondition.unconditional(), proxyClass);
}
Since:
25.0.1
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    register(AccessCondition condition, Class<?>... classes)
    Registers the provided classes for reflection at run time, if the condition is satisfied.
    void
    register(AccessCondition condition, Executable... executables)
    Registers the provided executables (methods and constructors) for reflective invocation at run time, if the condition is satisfied.
    void
    register(AccessCondition condition, Field... fields)
    Registers the provided fields for reflective access at run time, if the condition is satisfied.
    void
    registerForSerialization(AccessCondition condition, Class<?>... classes)
    Registers the provided classes for serialization at run time, if the condition is satisfied.
    void
    Registers the provided classes for unsafe allocation at run time, if the condition is satisfied.
    registerProxy(AccessCondition condition, Class<?>... interfaces)
    Registers a Proxy class in the system classloader that implements the specified interfaces, if the condition is satisfied.