Top Description Constructors Methods
org.graalvm.nativeimage.hosted

public final Class RuntimeReflection

extends Object
Class Inheritance
Annotations
@Platforms:HOSTED_ONLY
Imports
java.lang.reflect.Constructor, .Executable, .Field, .Modifier, org.graalvm.nativeimage.ImageSingletons, .Platform, .Platforms, org.graalvm.nativeimage.impl.ConfigurationCondition, .RuntimeReflectionSupport

This class provides methods that can be called during native image generation to register classes, methods, and fields for reflection at run time.
Since
19.0

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
register(Class<?>... classes)

Makes the provided classes available for reflection at run time.

public static void
register(Executable... methods)

Makes the provided methods available for reflection at run time.

public static void
register(Field... fields)

Makes the provided fields available for reflection at run time.

public static void
register(boolean finalIsWritable, Field... fields)
Deprecated since 21.1. Use register(Field...) instead.

public static void
register(boolean finalIsWritable, boolean allowUnsafeAccess, Field... fields)
Deprecated since 21.1. Use register(Field...) instead.

public static void
registerAllClasses(Class<?> declaringClass)

Allows calling Class#getClasses() on the provided class at run time.

public static void
registerAllConstructors(Class<?> declaringClass)

Allows calling Class#getConstructors() on the provided class at run time.

public static void
registerAllDeclaredClasses(Class<?> declaringClass)

Allows calling Class#getDeclaredClasses() on the provided class at run time.

public static void
registerAllDeclaredConstructors(Class<?> declaringClass)

Allows calling Class#getDeclaredConstructors() on the provided class at run time.

public static void
registerAllDeclaredFields(Class<?> declaringClass)

Allows calling Class#getDeclaredFields() on the provided class at run time.

public static void
registerAllDeclaredMethods(Class<?> declaringClass)

Allows calling Class#getDeclaredMethods() on the provided class at run time.

public static void
registerAllFields(Class<?> declaringClass)

Allows calling Class#getFields() on the provided class at run time.

public static void
registerAllMethods(Class<?> declaringClass)

Allows calling Class#getMethods() on the provided class at run time.

public static void
registerAllNestMembers(Class<?> declaringClass)

Allows calling Class#getNestMembers() on the provided class at run time.

public static void
registerAllPermittedSubclasses(Class<?> declaringClass)

Allows calling Class#getPermittedSubclasses() on the provided class at run time.

public static void
registerAllRecordComponents(Class<?> declaringClass)

Allows calling Class#getRecordComponents() on the provided class at run time.

public static void
registerAllSigners(Class<?> declaringClass)

Allows calling Class#getSigners() on the provided class at run time.

public static void
registerAsQueried(Executable... methods)

Makes the provided methods available for reflection queries at run time.

public static void
registerClassLookup(String className)

Makes the provided class available for reflection at run time.

public static void
registerConstructorLookup(Class<?> declaringClass, Class<?>... parameterTypes)

Makes the provided constructor available for reflection queries at run time.

public static void
registerFieldLookup(Class<?> declaringClass, String fieldName)

Makes the provided field available for reflection at run time.

public static void
registerForReflectiveInstantiation(Class<?>... classes)

Makes the provided classes available for reflective instantiation by Class#newInstance.

public static void
registerMethodLookup(Class<?> declaringClass, String methodName, Class<?>... parameterTypes)

Makes the provided method available for reflection queries at run time.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RuntimeReflectionback to summary
private RuntimeReflection()

Method Detail

registerback to summary
public static void register(Class<?>... classes)

Makes the provided classes available for reflection at run time. A call to Class#forName for the names of the classes will return the classes at run time.

Since
19.0
registerback to summary
public static void register(Executable... methods)

Makes the provided methods available for reflection at run time. The methods will be returned by Class#getMethod, Class#getDeclaredMethod(String, Class[]), and all the other methods on Class that return a single method.

Since
19.0
registerback to summary
public static void register(Field... fields)

Makes the provided fields available for reflection at run time. The fields will be returned by Class#getField, Class#getDeclaredField(String),and all the other methods on Class that return a single field.

Since
19.0
registerback to summary
public static void register(boolean finalIsWritable, Field... fields)

Deprecated

since 21.1.

Use register(Field...) instead. Parameter finalIsWritable no longer serves a purpose.

Annotations
@SuppressWarnings:unused
@Deprecated
since:21.1
Since
19.0
registerback to summary
public static void register(boolean finalIsWritable, boolean allowUnsafeAccess, Field... fields)

Deprecated

since 21.1.

Use register(Field...) instead. Parameters finalIsWritable and allowUnsafeAccess no longer serve a purpose.

Annotations
@SuppressWarnings:unused
@Deprecated
since:21.1
Since
21.0
registerAllClassesback to summary
public static void registerAllClasses(Class<?> declaringClass)

Allows calling Class#getClasses() on the provided class at run time.

Since
23.0
registerAllConstructorsback to summary
public static void registerAllConstructors(Class<?> declaringClass)

Allows calling Class#getConstructors() on the provided class at run time. The constructors will also be registered for individual queries.

Since
23.0
registerAllDeclaredClassesback to summary
public static void registerAllDeclaredClasses(Class<?> declaringClass)

Allows calling Class#getDeclaredClasses() on the provided class at run time.

Since
23.0
registerAllDeclaredConstructorsback to summary
public static void registerAllDeclaredConstructors(Class<?> declaringClass)

Allows calling Class#getDeclaredConstructors() on the provided class at run time. The constructors will also be registered for individual queries.

Since
23.0
registerAllDeclaredFieldsback to summary
public static void registerAllDeclaredFields(Class<?> declaringClass)

Allows calling Class#getDeclaredFields() on the provided class at run time. The fields will also be registered for individual queries.

Since
23.0
registerAllDeclaredMethodsback to summary
public static void registerAllDeclaredMethods(Class<?> declaringClass)

Allows calling Class#getDeclaredMethods() on the provided class at run time. The methods will also be registered for individual queries.

Since
23.0
registerAllFieldsback to summary
public static void registerAllFields(Class<?> declaringClass)

Allows calling Class#getFields() on the provided class at run time. The fields will also be registered for individual queries.

Since
23.0
registerAllMethodsback to summary
public static void registerAllMethods(Class<?> declaringClass)

Allows calling Class#getMethods() on the provided class at run time. The methods will also be registered for individual queries.

Since
23.0
registerAllNestMembersback to summary
public static void registerAllNestMembers(Class<?> declaringClass)

Allows calling Class#getNestMembers() on the provided class at run time.

Since
23.0
registerAllPermittedSubclassesback to summary
public static void registerAllPermittedSubclasses(Class<?> declaringClass)

Allows calling Class#getPermittedSubclasses() on the provided class at run time.

Since
23.0
registerAllRecordComponentsback to summary
public static void registerAllRecordComponents(Class<?> declaringClass)

Allows calling Class#getRecordComponents() on the provided class at run time.

Since
23.0
registerAllSignersback to summary
public static void registerAllSigners(Class<?> declaringClass)

Allows calling Class#getSigners() on the provided class at run time.

Since
23.0
registerAsQueriedback to summary
public static void registerAsQueried(Executable... methods)

Makes the provided methods available for reflection queries at run time. The methods will be returned by Class#getMethod, Class#getDeclaredMethod(String, Class[]), and all the other methods on Class that return a single method, but will not be invocable and will not be considered reachable.

Since
21.3
registerClassLookupback to summary
public static void registerClassLookup(String className)

Makes the provided class available for reflection at run time. A call to Class#forName for the name of the class will return the class (if it exists) or a ClassNotFoundException at run time.

Since
23.0
registerConstructorLookupback to summary
public static void registerConstructorLookup(Class<?> declaringClass, Class<?>... parameterTypes)

Makes the provided constructor available for reflection queries at run time. The constructor will be returned by Class#getConstructor, Class#getDeclaredConstructor(Class[]), and all the other methods on Class that return a single constructor, but will not be invocable and will not be considered reachable. If the constructor doesn't exist a NoSuchMethodException will be thrown when calling these methods at run-time.

Since
23.0
registerFieldLookupback to summary
public static void registerFieldLookup(Class<?> declaringClass, String fieldName)

Makes the provided field available for reflection at run time. The field will be returned by Class#getField, Class#getDeclaredField(String), and all the other methods on Class that return a single field. If the field doesn't exist a NoSuchFieldException will be thrown when calling these methods at run-time.

Since
19.0
registerForReflectiveInstantiationback to summary
public static void registerForReflectiveInstantiation(Class<?>... classes)

Makes the provided classes available for reflective instantiation by Class#newInstance. This is equivalent to registering the nullary constructors of the classes.

Since
19.0
registerMethodLookupback to summary
public static void registerMethodLookup(Class<?> declaringClass, String methodName, Class<?>... parameterTypes)

Makes the provided method available for reflection queries at run time. The method will be returned by Class#getMethod, Class#getDeclaredMethod(String, Class[]), and all the other methods on Class that return a single method, but will not be invocable and will not be considered reachable. If the method doesn't exist a NoSuchMethodException will be thrown when calling these methods at run-time.

Since
23.0