Chapter 6. Reflection
Reflection is the term for a set of features that allows a program to examine its own definition. Reflection in Java plays a role in class browsers, object inspectors, debuggers, interpreters, services such as JavaBeans™ and object serialization, and any tool that creates, inspects, or manipulates arbitrary Java objects on the fly.
Reflection was present in Java from the beginning, but the introduction of generics changed it in two important ways, introducing both generics for reflection and reflection for generics.
By generics for reflection we mean that some of the types used for reflection were now generic types. In particular, the class Class
became the generic class Class<T>
. We previously met these type tokens in “How to Create Arrays”, where we saw the special techniques that class literals and the Object
method getClass
use to return more-precise type information. In this section, we will see how generics ...
Get Java Generics and Collections, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.