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

Tries to load the class with the given name.

License

Open Source License

Parameter

Parameter Description
name The name of the class to load.
classLoader The class loader with which to load the class; if null, the current thread's context class loader will be used.

Declaration

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

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww  w.  j a va  2s.  c o  m
     * Tries to load the class with the given name.
     * <p>
     * This method uses the specified {@link ClassLoader} (or the current thread's
     * context class loader if {@code null} was passed as the {@code classLoader}
     * parameter. If the class cannot be found no exception is thrown but
     * {@code null} is returned instead.
     * </p>
     * <p>
     * This method is a stripped down version of the {@code loadClass} method in
     * SciJava-common's {@code ClassUtils} class.
     * </p>
     * 
     * @param name The name of the class to load.
     * @param classLoader The class loader with which to load the class; if null,
     *          the current thread's context class loader will be used.
     */
    static Class<?> loadClass(final String className, final ClassLoader classLoader) {
        // load the class!
        try {
            final ClassLoader cl = classLoader == null ? Thread.currentThread().getContextClassLoader()
                    : classLoader;
            return cl.loadClass(className);
        } catch (final ClassNotFoundException e) {
            return null;
        }
    }
}

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)
  6. loadClass(final String className, final ClassLoader classLoader)
  7. loadClass(final String clazz)
  8. loadClass(final String fqcn)
  9. loadClass(final String lclass)