Here you can find the source of classForName(String name)
Parameter | Description |
---|---|
name | Class name |
Parameter | Description |
---|---|
ClassNotFoundException | If the search class name does not match any class. |
public static Class<?> classForName(String name) throws ClassNotFoundException
//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); } }