Reflection
Explore runtime inspection and dynamic method and field access using Java reflection.
Reflection API
The reflection API lets Java code inspect classes, methods, fields, constructors, and annotations at runtime.
This is widely used by frameworks, dependency injection systems, and tooling.
Class Class
The Class object represents a runtime type and provides metadata and access to the class structure.
It is the fundamental entry point for reflective inspection in Java.
Method Class
Method objects encapsulate method metadata and support invocation at runtime.
They allow code to discover and call methods dynamically.
Field Class
Field objects represent class or instance variables and allow reading or writing them reflectively.
This is useful in frameworks and advanced inspection tools.
Constructor Class
Constructor objects represent class constructors and support reflective instantiation.
They enable creation of objects without direct compile-time knowledge of a specific type.
Dynamic Invocation
Dynamic invocation uses reflection to call methods or constructors without compile-time linkage.
This provides flexibility but requires careful validation and error handling.
Dynamic Proxy
Dynamic proxies generate implementations of interfaces at runtime, allowing interception and delegation patterns.
This is a common technique in frameworks such as AOP and proxy-based instrumentation.
Reflection Performance
Reflection is usually slower than direct method calls because it performs runtime checks and dynamic resolution.
This is one reason frameworks should use reflection carefully and cache metadata where possible.