Java Class Load loadClassByName(String className)

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

Description

Load Class by class name.

License

Apache License

Parameter

Parameter Description
className Canonical class name

Exception

Parameter Description
ClassNotFoundException an exception

Return

Class definition of className

Declaration

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

Method Source Code

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

public class Main {
    /**/*ww w.j ava  2s .  c  o m*/
     * Load Class by class name. If class not found in it's Class loader or one of the parent class loaders - delegate to the Thread's ContextClassLoader
     *
     * @param className Canonical class name
     * @return Class definition of className
     * @throws ClassNotFoundException
     */
    public static Class<?> loadClassByName(String className) throws ClassNotFoundException {
        try {
            return Class.forName(className);
        } catch (ClassNotFoundException e) {
            return Thread.currentThread().getContextClassLoader().loadClass(className);
        }
    }
}

Related

  1. loadClass(String name, ClassLoader ldr)
  2. loadClass(String name, ClassLoader loader)
  3. loadClass(String theClassName, Class theReferrer)
  4. loadClass(T instance)
  5. loadClassByName(final String className, final ClassLoader loader)
  6. loadClassElseThrow(final String enumType)
  7. loadClassFromClassLoader( String fillyQualifiedClassName)
  8. loadClassFromContextClassLoader(String theClassName)
  9. loadClassOrNull(String className)