Package org.graalvm.nativeimage.hosted
Class RuntimeReflection
java.lang.Object
org.graalvm.nativeimage.hosted.RuntimeReflection
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Deprecated.static void
Deprecated.Useregister(Field...)
instead.static void
Makes the provided classes available for reflection at run time.static void
register
(Executable... methods) Makes the provided methods available for reflection at run time.static void
Makes the provided fields available for reflection at run time.static void
registerAllClasses
(Class<?> declaringClass) Allows callingClass.getClasses()
on the provided class at run time.static void
registerAllConstructors
(Class<?> declaringClass) Allows callingClass.getConstructors()
on the provided class at run time.static void
registerAllDeclaredClasses
(Class<?> declaringClass) Allows callingClass.getDeclaredClasses()
on the provided class at run time.static void
registerAllDeclaredConstructors
(Class<?> declaringClass) Allows callingClass.getDeclaredConstructors()
on the provided class at run time.static void
registerAllDeclaredFields
(Class<?> declaringClass) Allows callingClass.getDeclaredFields()
on the provided class at run time.static void
registerAllDeclaredMethods
(Class<?> declaringClass) Allows callingClass.getDeclaredMethods()
on the provided class at run time.static void
registerAllFields
(Class<?> declaringClass) Allows callingClass.getFields()
on the provided class at run time.static void
registerAllMethods
(Class<?> declaringClass) Allows callingClass.getMethods()
on the provided class at run time.static void
registerAllNestMembers
(Class<?> declaringClass) Allows callingClass.getNestMembers()
on the provided class at run time.static void
registerAllPermittedSubclasses
(Class<?> declaringClass) Allows callingClass.getPermittedSubclasses()
on the provided class at run time.static void
registerAllRecordComponents
(Class<?> declaringClass) Allows callingClass.getRecordComponents()
on the provided class at run time.static void
registerAllSigners
(Class<?> declaringClass) Allows callingClass.getSigners()
on the provided class at run time.static void
registerAsQueried
(Executable... methods) Makes the provided methods available for reflection queries at run time.static void
registerClassLookup
(String className) Makes the provided class available for reflection at run time.static void
registerConstructorLookup
(Class<?> declaringClass, Class<?>... parameterTypes) Makes the provided constructor available for reflection queries at run time.static void
registerFieldLookup
(Class<?> declaringClass, String fieldName) Makes the provided field available for reflection at run time.static void
registerForReflectiveInstantiation
(Class<?>... classes) Makes the provided classes available for reflective instantiation byClass.newInstance()
.static void
registerMethodLookup
(Class<?> declaringClass, String methodName, Class<?>... parameterTypes) Makes the provided method available for reflection queries at run time.
-
Method Details
-
register
Makes the provided classes available for reflection at run time. A call toClass.forName(java.lang.String)
for the names of the classes will return the classes at run time.- Since:
- 19.0
-
registerClassLookup
Makes the provided class available for reflection at run time. A call toClass.forName(java.lang.String)
for the name of the class will return the class (if it exists) or aClassNotFoundException
at run time.- Since:
- 23.0
-
register
Makes the provided methods available for reflection at run time. The methods will be returned byClass.getMethod(java.lang.String, java.lang.Class<?>...)
,Class.getDeclaredMethod(String, Class[])
, and all the other methods onClass
that return a single method.- Since:
- 19.0
-
registerAsQueried
Makes the provided methods available for reflection queries at run time. The methods will be returned byClass.getMethod(java.lang.String, java.lang.Class<?>...)
,Class.getDeclaredMethod(String, Class[])
, and all the other methods onClass
that return a single method, but will not be invocable and will not be considered reachable.- Since:
- 21.3
-
registerMethodLookup
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 byClass.getMethod(java.lang.String, java.lang.Class<?>...)
,Class.getDeclaredMethod(String, Class[])
, and all the other methods onClass
that return a single method, but will not be invocable and will not be considered reachable. If the method doesn't exist aNoSuchMethodException
will be thrown when calling these methods at run-time.- Since:
- 23.0
-
registerConstructorLookup
Makes the provided constructor available for reflection queries at run time. The constructor will be returned byClass.getConstructor(java.lang.Class<?>...)
,Class.getDeclaredConstructor(Class[])
, and all the other methods onClass
that return a single constructor, but will not be invocable and will not be considered reachable. If the constructor doesn't exist aNoSuchMethodException
will be thrown when calling these methods at run-time.- Since:
- 23.0
-
register
Makes the provided fields available for reflection at run time. The fields will be returned byClass.getField(java.lang.String)
,Class.getDeclaredField(String)
,and all the other methods onClass
that return a single field.- Since:
- 19.0
-
registerFieldLookup
Makes the provided field available for reflection at run time. The field will be returned byClass.getField(java.lang.String)
,Class.getDeclaredField(String)
, and all the other methods onClass
that return a single field. If the field doesn't exist aNoSuchFieldException
will be thrown when calling these methods at run-time.- Since:
- 19.0
-
registerAllClasses
Allows callingClass.getClasses()
on the provided class at run time.- Since:
- 23.0
-
registerAllDeclaredClasses
Allows callingClass.getDeclaredClasses()
on the provided class at run time.- Since:
- 23.0
-
registerAllMethods
Allows callingClass.getMethods()
on the provided class at run time. The methods will also be registered for individual queries.- Since:
- 23.0
-
registerAllDeclaredMethods
Allows callingClass.getDeclaredMethods()
on the provided class at run time. The methods will also be registered for individual queries.- Since:
- 23.0
-
registerAllConstructors
Allows callingClass.getConstructors()
on the provided class at run time. The constructors will also be registered for individual queries.- Since:
- 23.0
-
registerAllDeclaredConstructors
Allows callingClass.getDeclaredConstructors()
on the provided class at run time. The constructors will also be registered for individual queries.- Since:
- 23.0
-
registerAllFields
Allows callingClass.getFields()
on the provided class at run time. The fields will also be registered for individual queries.- Since:
- 23.0
-
registerAllDeclaredFields
Allows callingClass.getDeclaredFields()
on the provided class at run time. The fields will also be registered for individual queries.- Since:
- 23.0
-
registerAllNestMembers
Allows callingClass.getNestMembers()
on the provided class at run time.- Since:
- 23.0
-
registerAllPermittedSubclasses
Allows callingClass.getPermittedSubclasses()
on the provided class at run time.- Since:
- 23.0
-
registerAllRecordComponents
Allows callingClass.getRecordComponents()
on the provided class at run time.- Since:
- 23.0
-
registerAllSigners
Allows callingClass.getSigners()
on the provided class at run time.- Since:
- 23.0
-
register
Deprecated.Useregister(Field...)
instead. ParameterfinalIsWritable
no longer serves a purpose.- Since:
- 19.0
-
register
@Deprecated(since="21.1") public static void register(boolean finalIsWritable, boolean allowUnsafeAccess, Field... fields) Deprecated.Useregister(Field...)
instead. ParametersfinalIsWritable
andallowUnsafeAccess
no longer serve a purpose.- Since:
- 21.0
-
registerForReflectiveInstantiation
Makes the provided classes available for reflective instantiation byClass.newInstance()
. This is equivalent to registering the nullary constructors of the classes.- Since:
- 19.0
-
register(Field...)
instead.