Class Inspection with Reflection
Retrieve Class objects, inspect fields, methods, constructors, and annotations at runtime.
What Is Reflection?
Reflection allows a Java program to inspect and manipulate its own structure at runtime — reading class names, fields, methods, constructors, and annotations without knowing them at compile time.
Obtaining a Class Object
Get a Class<?> object via the literal, getClass(), or Class.forName().
Class<String> c1 = String.class; // literal
Class<?> c2 = "hello".getClass(); // from instance
Class<?> c3 = Class.forName("java.util.ArrayList"); // by nameAll lessons in this course
- Class Inspection with Reflection
- Invoking Methods and Accessing Fields
- Dynamic Proxies with InvocationHandler
- Reflection Performance and Alternatives