0Pricing
Java Academy · Lesson

Reflection and Configuration

Handle dynamic features.

Reflection and Configuration

Native-image's closed-world analysis can only see code it can trace statically. Dynamic features — reflection, proxies, resources, and serialization — hide their targets from the analyzer. This lesson explains how to make them work in a native binary.

The Problem with Reflection

When you look up a class by name from a string, the analyzer cannot know which class you mean. If that class is otherwise unreachable, it will be excluded from the image and the lookup fails at runtime.

public class Main {
    public static void main(String[] args) throws Exception {
        String name = "java.util.ArrayList"; // could come from config
        Class<?> c = Class.forName(name);
        System.out.println("Loaded: " + c.getSimpleName());
    }
}

All lessons in this course

  1. What Is GraalVM
  2. Building a Native Image
  3. Reflection and Configuration
  4. Trade-offs of Native Image
← Back to Java Academy