Answers for "how to get class from string in java"

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();
Posted by: Guest on December-27-2020
0

java class from string

import java.lang.reflect.*;

Param1Type param1;
Param2Type param2;
String className = "Class1";
Class cl = Class.forName(className);
Constructor con = cl.getConstructor(Param1Type.class, Param2Type.class);
Object xyz = con.newInstance(param1, param2);
Posted by: Guest on August-20-2020

Code answers related to "how to get class from string in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language