Convert exception to error to preseve the interface. In some cases code is written with dynamic dependencies between parts of the code by utilising Java ability to load and instantiate arbitrary classes. If not properly managed, this can cause run-time errors. This design can impart a performance penalty because of the extra levels of indirection. It can also prevent the compiler from detecting certian types of error.
Mechanics Identify the places where the different classes are instantiated.
If there is more than one place, you might like to make use of code consolidation refactorings to create one entry point. You can remove the code that instantiates the classes using java.lang.reflect. We will instead call the constructors directly. Replace the code that selects the name of the class with simpler code that simply returns a new instance. Add in import statements as required for the classes being constructed.