Java Class Load classForName(String name)

Here you can find the source of classForName(String name)

Description

Get a class for its name.

License

Open Source License

Parameter

Parameter Description
name Class name

Exception

Parameter Description
ClassNotFoundException If the search class name does not match any class.

Return

a Class instance

Declaration

public static Class<?> classForName(String name)
        throws ClassNotFoundException 

Method Source Code

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

public class Main {
    /**//  w  w  w.  ja  va  2  s.c  om
     * Get a class for its name.
     * 
     * @param name Class name
     * @return a Class instance
     * @throws ClassNotFoundException If the search class name does not match any class.
     */
    public static Class<?> classForName(String name)
            throws ClassNotFoundException {
        if (name.equals("boolean"))
            return boolean.class;
        else if (name.equals("byte"))
            return byte.class;
        else if (name.equals("short"))
            return short.class;
        else if (name.equals("char"))
            return char.class;
        else if (name.equals("int"))
            return int.class;
        else if (name.equals("long"))
            return long.class;
        else if (name.equals("float"))
            return float.class;
        else if (name.equals("double"))
            return double.class;
        else
            return Class.forName(name);
    }
}

Related

  1. classForName(String clazzName, ClassLoader classLoader)
  2. classForName(String cname)
  3. classForName(String columnType)
  4. classForName(String listener)
  5. classForName(String name)
  6. classForName(String name)
  7. classForName(String name)
  8. classForName(String name)
  9. classForName(String name)