Get Class given its fully qualified name
suggest changeGiven 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);
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents