Class RuntimeReflection

java.lang.Object
org.graalvm.nativeimage.hosted.RuntimeReflection

public final class RuntimeReflection extends Object
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 Details

    • register

      public static void register(Class<?>... classes)
      Makes the provided classes available for reflection at run time. A call to Class.forName(java.lang.String) for the names of the classes will return the classes at run time.
      Since:
      19.0
    • registerClassLookup

      public static void registerClassLookup(String className)
      Makes the provided class available for reflection at run time. A call to Class.forName(java.lang.String) for the name of the class will return the class (if it exists) or a ClassNotFoundException at run time.
      Since:
      23.0
    • register

      public static void register(Executable... methods)
      Makes the provided methods available for reflection at run time. The methods will be returned by Class.getMethod(java.lang.String, java.lang.Class<?>...), Class.getDeclaredMethod(String, Class[]), and all the other methods on Class that return a single method.
      Since:
      19.0
    • registerAsQueried

      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(java.lang.String, java.lang.Class<?>...), 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
    • 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 by Class.getMethod(java.lang.String, java.lang.Class<?>...), 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
    • registerConstructorLookup

      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(java.lang.Class<?>...), 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
    • register

      public static void register(Field... fields)
      Makes the provided fields available for reflection at run time. The fields will be returned by Class.getField(java.lang.String), Class.getDeclaredField(String),and all the other methods on Class that return a single field.
      Since:
      19.0
    • registerFieldLookup

      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(java.lang.String), 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
    • registerAllClasses

      public static void registerAllClasses(Class<?> declaringClass)
      Allows calling Class.getClasses() on the provided class at run time.
      Since:
      23.0
    • registerAllDeclaredClasses

      public static void registerAllDeclaredClasses(Class<?> declaringClass)
      Allows calling Class.getDeclaredClasses() on the provided class at run time.
      Since:
      23.0
    • registerAllMethods

      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
    • registerAllDeclaredMethods

      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
    • registerAllConstructors

      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
    • registerAllDeclaredConstructors

      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
    • registerAllFields

      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
    • registerAllDeclaredFields

      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
    • registerAllNestMembers

      public static void registerAllNestMembers(Class<?> declaringClass)
      Allows calling Class.getNestMembers() on the provided class at run time.
      Since:
      23.0
    • registerAllPermittedSubclasses

      public static void registerAllPermittedSubclasses(Class<?> declaringClass)
      Allows calling Class.getPermittedSubclasses() on the provided class at run time.
      Since:
      23.0
    • registerAllRecordComponents

      public static void registerAllRecordComponents(Class<?> declaringClass)
      Allows calling Class.getRecordComponents() on the provided class at run time.
      Since:
      23.0
    • registerAllSigners

      public static void registerAllSigners(Class<?> declaringClass)
      Allows calling Class.getSigners() on the provided class at run time.
      Since:
      23.0
    • register

      @Deprecated(since="21.1") public static void register(boolean finalIsWritable, Field... fields)
      Deprecated.
      Use register(Field...) instead. Parameter finalIsWritable no longer serves a purpose.
      Since:
      19.0
    • register

      @Deprecated(since="21.1") public static void register(boolean finalIsWritable, boolean allowUnsafeAccess, Field... fields)
      Deprecated.
      Use register(Field...) instead. Parameters finalIsWritable and allowUnsafeAccess no longer serve a purpose.
      Since:
      21.0
    • registerForReflectiveInstantiation

      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