Get Class given its fully qualified name

suggest change

Given a String containing the name of a class, it’s Class object can be accessed using Class.forName:

Class clazz = null;
try {
    clazz = Class.forName("java.lang.Integer");
} catch (ClassNotFoundException ex) {
    throw new IllegalStateException(ex);
}

It can be specified, if the class should be initialized (second parameter of forName) and which ClassLoader should be used (third parameter):

ClassLoader classLoader = ...
boolean initialize = ...
Class clazz = null;
try {
    clazz = Class.forName("java.lang.Integer", initialize, classLoader);
} catch (ClassNotFoundException ex) {
    throw new IllegalStateException(ex);
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents