Edited 2021-02-08 to reflect API changes for Java 11.
There are a number of cases when you may not know exactly what class you will be instantiating and want to be able to dynamically instantiate specific classes based on a configuration file or a condition during runtime.
To do so, you will need to define a parent class, abstract class, or interface for your classes and can then use the following code as a guide.
Given the following class definitions:→ Continue reading “Dynamically Instantiating Classes in Java”