Get Class given its fully qualified name

suggest change

Given a String containing the binary name of a class, its Class object can be loaded with Class.forName. The one-argument form initializes the class and uses the caller's class loader:

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

The three-argument form chooses whether the class is initialized and which ClassLoader loads it. A null loader means the bootstrap class loader. Primitive names such as "int" are not accepted; Class.forName("int") throws ClassNotFoundException.

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