java get class by string code example
Example 1: java get class by string
//get an according class variable
String className = "MyClass";
Class<?> cls = Class.forName(className);
//create instance of that class
Object myInstance = cls.newInstance();
Example 2: java get class by string name
//get an according class variable
String className = "MyClass";
Class<?> cls = Class.forName(className);
//create instance of that class
Object myInstance = scl.newInstance();