ClassLoaders and Instantiation
Explore how Java reflection allows for dynamic object creation at runtime and how ClassLoaders find and load classes. Learn safe methods to instantiate objects, including invoking parameterized constructors and managing accessibility. Understand how these concepts impact design patterns and application architecture.
We'll cover the following...
Reflection provides powerful mechanisms to create objects at runtime. However, we must use modern, safe approaches to instantiate these objects.
Let’s start by exploring dynamic instantiation and then dive into the ClassLoaders that make loading and linking these classes possible.
How can we create class instances using reflection?
To demonstrate the safe approach to instantiation, let’s look at the following example where we invoke a parameterized constructor:
...