This class provides two different registration methods: Classes registered via
initializeAtRunTime are not initialized at all during image generation, and only
initialized at runtime, i.e., the class initializer is executed once at runtime. Classes
registered via initializeAtBuildTime will be initialized during image building.
It is also possible define initialization for whole packages with
initializeAtRunTime(String[]) and initializeAtBuildTime(String[]). The rules
for packages can be further refined by using methods for individual classes.
Initializing classes at runtime comes with some costs and restrictions:
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static String | |
| private static String | |
| private static String | getUnqualifiedName(Class<?> aClass)
Alternative to |
| public static void | initializeAtBuildTime(Class<?>... classes)
Registers the provided classes as eagerly initialized during image-build time. |
| public static void | initializeAtBuildTime(String... packages)
Registers all classes in provided packages as eagerly initialized during image-build time. |
| public static void | initializeAtRunTime(Class<?>... classes)
Registers the provided classes, and all of their subclasses, for class initialization at runtime. |
| public static void | initializeAtRunTime(String... packages)
Registers all classes in provided packages, and all of their subclasses, for class initialization at runtime. |
| RuntimeClassInitialization | back to summary |
|---|---|
| private RuntimeClassInitialization() | |
| classReason | back to summary |
|---|---|
| private static String classReason(StackTraceElement[] stacktrace, String simpleName) | |
| getCaller | back to summary |
|---|---|
| private static String getCaller(StackTraceElement[] stackTrace) | |
| getUnqualifiedName | back to summary |
|---|---|
| private static String getUnqualifiedName(Class<?> aClass) Alternative to | |
| initializeAtBuildTime | back to summary |
|---|---|
| public static void initializeAtBuildTime(Class<?>... classes) Registers the provided classes as eagerly initialized during image-build time.
All static initializers of It is up to the user to ensure that this behavior makes sense and does not lead to wrong application behavior. After this method returns, all listed classes are initialized in the VM that runs the image generator. Therefore, this method can be used to resolve deadlocks and cycles in class initializer by starting initialization with a known-good entry class. All superclasses and superinterfaces that are initialized before any of the listed classes are registered for initialization at build time too. Please look at the Java specification for the exact rules, especially regarding interfaces that declare default methods.
| |
| initializeAtBuildTime | back to summary |
|---|---|
| public static void initializeAtBuildTime(String... packages) Registers all classes in provided packages as eagerly initialized during image-build time.
Passing
All static initializers of It is up to the user to ensure that this behavior makes sense and does not lead to wrong application behavior.
| |
| initializeAtRunTime | back to summary |
|---|---|
| public static void initializeAtRunTime(Class<?>... classes) Registers the provided classes, and all of their subclasses, for class initialization at runtime. The classes are not initialized automatically during image generation, and also must not be initialized manually by the user during image generation. Unfortunately, classes are initialized for many reasons, and it is not possible to intercept class initialization and report an error at this time. If a registered class gets initialized, an error can be reported only later and the user must manually debug the reason for class initialization. This can be done by, e.g., setting a breakpoint in the class initializer or adding debug printing (print the stack trace) in the class initializer.
| |
| initializeAtRunTime | back to summary |
|---|---|
| public static void initializeAtRunTime(String... packages) Registers all classes in provided packages, and all of their subclasses, for class initialization at runtime. The classes are not initialized automatically during image generation, and also must not be initialized manually by the user during image generation. Unfortunately, classes are initialized for many reasons, and it is not possible to intercept class initialization and report an error at this time. If a registered class gets initialized, an error can be reported only later and the user must manually debug the reason for class initialization. This can be done by, e.g., setting a breakpoint in the class initializer or adding debug printing (print the stack trace) in the class initializer.
| |