Java Class Load loadClass(String className)

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

Description

load Class

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 - 2013 Spring IDE Developers
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  ww w  .j  a  v  a 2 s .c  o  m*/
 *     Spring IDE Developers - initial API and implementation
 *******************************************************************************/

public class Main {
    public static Class<?> loadClass(String className) throws ClassNotFoundException {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        return loadClass(className, loader);
    }

    public static Class<?> loadClass(Class clazz) throws ClassNotFoundException {
        return loadClass(clazz.getName());
    }

    public static Class<?> loadClass(String className, ClassLoader loader) throws ClassNotFoundException {
        try {
            return loader.loadClass(className);
        } catch (ClassNotFoundException ex) {
            int lastDotIndex = className.lastIndexOf('.');
            if (lastDotIndex != -1) {
                String innerClassName = className.substring(0, lastDotIndex) + '$'
                        + className.substring(lastDotIndex + 1);
                try {
                    return loader.loadClass(innerClassName);
                } catch (ClassNotFoundException ex2) {
                    // swallow - let original exception get through
                }
            }
            throw ex;
        }
    }
}

Related

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