Reflection is the name given to inspecting code at runtime instead of compile time. It can be used to create instances of classes, look up functions and invoke them, inspect annotations, find fields, and discover parameters and generics, all without knowing those details at compile time.
For example, we might want to persist types into a database, but we don't know, or don't want to have to know, in advance which types will be persisted. Reflection could be used to look up the fields of each type, creating the appropriate SQL code for each type.
Another example would be if we had a plugin system in our code, and at runtime we wanted to create instances of the plugin based on config or system properties. We could use reflection to instantiate classes based on the fully qualified name passed in.
For the rest of this chapter, we will cover the various reflection...