Lesson content
Read, practise, then check your understanding
Reflection exposes loaded-type metadata through Class, fields, constructors, methods, annotations, and generic descriptors.
Runtime inspection
Class<?> type = Class.forName("com.example.Plugin");
for (Method method : type.getDeclaredMethods()) {
System.out.println(method.getName());
}
Reflective invocation loses compile-time checking, can wrap failures, and may be slower or restricted by modules. Do not bypass encapsulation casually with accessible overrides. Cache validated metadata when appropriate and whitelist permitted types/members for untrusted configuration. Prefer interfaces, factories, method handles, or generated code when the relationship is known at compile time.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.