java get class by string

Solutions on MaxInterview for java get class by string by the best coders in the world

showing results for - "java get class by string"
Martín
01 Aug 2017
1//get an according class variable
2String className = "MyClass";
3Class<?> cls = Class.forName(className);
4
5//create instance of that class
6Object myInstance = cls.newInstance();
Eleonora
28 Jan 2020
1//get an according class variable
2String className = "MyClass";
3Class<?> cls = Class.forName(className);
4
5//create instance of that class
6Object myInstance = scl.newInstance();