Get Class from class name
static Class<?> forName(String className)
- Returns the Class object associated with the class or interface with the given string name.
static Class<?> forName(String name, boolean initialize, ClassLoader loader)
- Returns the Class object associated with the class or interface with the given string name, using the given class loader.
Use Class.forName to create Class from a String
public class Main {
public static void main(String[] args) {
try {
Class c = Class.forName("java.lang.String");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}