Java Class Load getClass(String className)

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

Description

get Class

License

LGPL

Declaration

public static Class getClass(String className) throws ClassNotFoundException 

Method Source Code

//package com.java2s;
/*//  w  w w .  j a va 2 s  .  c  o m
 * JFox - The most lightweight Java EE Application Server!
 * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
 *
 * JFox is licenced and re-distributable under GNU LGPL.
 */

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static Map<String, Class> primitiveStringToClass = new HashMap<String, Class>();

    public static Class getClass(String className) throws ClassNotFoundException {
        Class clazz;
        if (isPrimitiveClass(className)) {
            return primitiveStringToClass.get(className);
        } else {
            clazz = Class.forName(className);
        }
        return clazz;
    }

    public static Class getClass(ClassLoader classLoader, String className) throws ClassNotFoundException {
        Class clazz;
        if (isPrimitiveClass(className)) {
            return primitiveStringToClass.get(className);
        } else {
            clazz = classLoader.loadClass(className);
        }
        return clazz;
    }

    public static boolean isPrimitiveClass(String primitiveClassName) {
        return primitiveStringToClass.containsKey(primitiveClassName);
    }

    public static boolean isPrimitiveClass(Class primitiveClass) {
        return primitiveStringToClass.containsKey(primitiveClass.getName());
    }
}

Related

  1. fromString(Class enumType, String text)
  2. fromString(final Class clazz, final String value)
  3. fromString(String string, Class arrayClass)
  4. getClass(Class clazz)
  5. getClass(String className)
  6. getClass(String className)
  7. getClass(String fullClassName)
  8. getClass(String name)
  9. getClass(String name)