Java Class Load loadClass(final String className, final ClassLoader classLoader)

Here you can find the source of loadClass(final String className, final ClassLoader classLoader)

Description

Helper method to load a class.

License

Open Source License

Parameter

Parameter Description
className is the class to instantiate
classLoader the class loader to use; may be null if the current class loader is to be used

Exception

Parameter Description
ClassNotFoundException an exception

Return

Class is the instance of the class

Declaration

private static final Class<?> loadClass(final String className, final ClassLoader classLoader)
        throws ClassNotFoundException 

Method Source Code

//package com.java2s;
/*//from  w  w w  . jav a2s  .c o  m
 * JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/

public class Main {
    /**
     * Helper method to load a class.
     * @param className is the class to instantiate
     * @param classLoader the class loader to use; may be null if the current
     * class loader is to be used
     * @return Class is the instance of the class 
     * @throws ClassNotFoundException 
     */
    private static final Class<?> loadClass(final String className, final ClassLoader classLoader)
            throws ClassNotFoundException {
        Class<?> cls = null;
        if (classLoader == null) {
            cls = Class.forName(className.trim());
        } else {
            cls = Class.forName(className.trim(), true, classLoader);
        }
        return cls;
    }
}

Related

  1. loadClass(final String className)
  2. loadClass(final String className)
  3. loadClass(final String className)
  4. loadClass(final String className)
  5. loadClass(final String className, final ClassLoader classLoader)
  6. loadClass(final String clazz)
  7. loadClass(final String fqcn)
  8. loadClass(final String lclass)
  9. loadClass(final String packageName, final String className)