Java Class Load classForNameOrPrimitive(String name, ClassLoader loader)

Here you can find the source of classForNameOrPrimitive(String name, ClassLoader loader)

Description

class For Name Or Primitive

License

Open Source License

Parameter

Parameter Description
name FQN of a class, or the name of a primitive type
loader a ClassLoader

Return

the Class for the name given. Primitive types are converted to their particular Class object. null, the empty string, "null", and "void" yield Void.TYPE. If any classes require loading because of this operation, the loading is done by the given class loader. Such classes are not initialized, however.

Declaration

static Class classForNameOrPrimitive(String name, ClassLoader loader) throws ClassNotFoundException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w  w  w . j a  v  a 2s .c o m*/
     * @param  name  FQN of a class, or the name of a primitive type
     * @param  loader  a ClassLoader
     * @return  the Class for the name given.  Primitive types are
     * converted to their particular Class object.  null, the empty string,
     * "null", and "void" yield Void.TYPE.  If any classes require
     * loading because of this operation, the loading is done by the
     * given class loader.  Such classes are not initialized, however.
     * @exception  ClassNotFoundException  if name names an
     * unknown class or primitive
     */
    static Class classForNameOrPrimitive(String name, ClassLoader loader) throws ClassNotFoundException {
        if (name == null || name.equals("") || name.equals("null") || name.equals("void"))
            return Void.TYPE;
        if (name.equals("boolean"))
            return Boolean.TYPE;
        if (name.equals("byte"))
            return Byte.TYPE;
        if (name.equals("char"))
            return Character.TYPE;
        if (name.equals("double"))
            return Double.TYPE;
        if (name.equals("float"))
            return Float.TYPE;
        if (name.equals("int"))
            return Integer.TYPE;
        if (name.equals("long"))
            return Long.TYPE;
        if (name.equals("short"))
            return Short.TYPE;
        return Class.forName(name, false, loader);
    }
}

Related

  1. classForName(String str)
  2. classForName(String typeName)
  3. classForName(String typeName)
  4. classForNameNoThrow(String className)
  5. classForNameOrNull(final String className)
  6. fromString(Class clazz, String stringValue)
  7. fromString(Class clazz, String name)
  8. fromString(Class clz, String value, T defaultVal)
  9. fromString(Class enumClass, String s, T defaultValue)