Java Class Load loadClass(String className)

Here you can find the source of loadClass(String className)

Description

Load class from the previously set class loader.

License

Apache License

Parameter

Parameter Description
className class name

Return

the loaded class

Declaration

public static Class<?> loadClass(String className) throws ClassNotFoundException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static ClassLoader currentClassLoader;

    /**/*w  w  w  .  j a va2s.c o m*/
     * Load class from the previously set class loader. If not set, use
     * default class loader
     *
     * @param       className       class name
     * @return      the loaded class
     */
    public static Class<?> loadClass(String className) throws ClassNotFoundException {
        ClassLoader loader = currentClassLoader;
        if (loader == null) {
            loader = Thread.currentThread().getContextClassLoader();
        }
        try {
            return Class.forName(className, false, loader);
        } catch (ClassNotFoundException e) {
            ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
            if (contextLoader != loader) {
                return Class.forName(className, false, contextLoader);
            }
            throw e;
        }
    }
}

Related

  1. loadClass(String className)
  2. loadClass(String className)
  3. loadClass(String className)
  4. loadClass(String className)
  5. loadClass(String className)
  6. loadClass(String className)
  7. loadClass(String className)
  8. loadClass(String className)
  9. loadClass(String className)