Here you can find the source of classForNameOrPrimitive(String name, ClassLoader loader)
Parameter | Description |
---|---|
name | FQN of a class, or the name of a primitive type |
loader | a ClassLoader |
static Class classForNameOrPrimitive(String name, ClassLoader loader) throws ClassNotFoundException
//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); } }