Answers for "java get class name in string"

2

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
2

java get classname

//Just the name of the class
myObject.getClass().getSimpleName();

//The name of the class with the package name
myObject.getClass().getName();
Posted by: Guest on March-23-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language