Interface reflection
Introduction / Definition
Reflection allows a program or runtime to inspect type or member information dynamically. It is useful in frameworks, testing, dependency injection, and serialization. Reflection can discover methods, fields, or annotations. It should be used carefully because it can reduce clarity and may have performance or security implications.
Syntax / Structure / Formula
Reflection โ inspect metadata โ discover members โ use permitted members
Detailed Explanation
A framework can inspect a class and register methods marked with a particular annotation. This avoids hard-coding every handler.
Example
Example: A Java framework discovers annotated request-handler methods.
Output / Result
The framework registers handlers based on runtime metadata.
Important Points / Notes
- Reflection is runtime/language dependent.
- Prefer explicit interfaces when possible.
Mini Practice Question
Give one use of reflection.