0Pricing
Java Academy · Lesson

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 name

All lessons in this course

  1. Class Inspection with Reflection
  2. Invoking Methods and Accessing Fields
  3. Dynamic Proxies with InvocationHandler
  4. Reflection Performance and Alternatives
← Back to Java Academy