Java Utililty Methods Class Load

List of utility methods to do Class Load

Description

The list of methods to do Class Load are organized into topic(s).

Method

ClassloadClass(String name)
Load class through our application classpath, plus optionally try to resolve from the additional classpath.
return Class.forName(name, true, CL);
ClassloadClass(String name)
Loads the class with the specified name.
return loadClass(name, null);
ClassloadClass(String name, ClassLoader cl)
First checks if name is a primitive type.
if (name.equals(void.class.getName())) {
    return void.class;
if (name.equals(byte.class.getName())) {
    return byte.class;
if (name.equals(short.class.getName())) {
    return short.class;
...
ClassloadClass(String name, ClassLoader ldr)
load Class
try {
    return Class.forName(name, true, ldr);
} catch (ClassNotFoundException e) {
    return null;
ClassloadClass(String name, ClassLoader loader)
Load class or throw exception
try {
    return loader.loadClass(name);
} catch (ClassNotFoundException e) {
    fatal("Class " + name + " not found.", e);
    return null;
ClassloadClass(String theClassName, Class theReferrer)
Try loading a class first by using the context class loader or by using the classloader of the referrer class if the context classloader failed to load the class.
Class clazz = null;
try {
    clazz = loadClassFromWebappClassLoader(theClassName, theReferrer);
} catch (Throwable internalException) {
    clazz = loadClassFromContextClassLoader(theClassName);
return clazz;
ClassloadClass(T instance)
load Class
if (instance != null) {
    return (Class<T>) instance.getClass();
return null;
ClassloadClassByName(final String className, final ClassLoader loader)
Loads a class by name
try {
    if (loader != null) {
        return Class.forName(className, true, loader);
    return Class.forName(className);
} catch (Exception ex) {
    return null;
ClassloadClassByName(String className)
Load Class by class name.
try {
    return Class.forName(className);
} catch (ClassNotFoundException e) {
    return Thread.currentThread().getContextClassLoader().loadClass(className);
ClassloadClassElseThrow(final String enumType)
load Class Else Throw
try {
    return (Class<T>) loadClass(enumType);
} catch (ClassNotFoundException e) {
    throw new RuntimeException(e);