Here you can find the source of classForName(String className)
public static <T> Class<T> classForName(String className) throws Exception
//package com.java2s; //License from project: Apache License import java.util.HashMap; import java.util.Map; public class Main { private static Map<Object, Class<?>> __primitiveTypes = new HashMap<Object, Class<?>>(); public static <T> Class<T> classForName(String className) throws Exception { Class c = __primitiveTypes.get(className); if (null != c) return c; try {//from ww w. j a v a2s . co m return (Class<T>) Class.forName(className); } catch (ClassNotFoundException e) { throw new Exception(e); } } public static <T> Class<T> classForName(String className, ClassLoader classLoader) throws Exception { Class c = __primitiveTypes.get(className); if (null != c) return c; try { if (className.contains("[")) { StringBuffer buffer = new StringBuffer(); className = buffer.append("[L").append(beforeFirst(className, "[")).append(";").toString(); } return (Class<T>) Class.forName(className, true, classLoader); } catch (ClassNotFoundException e) { throw new Exception(e); } } public static String beforeFirst(String s0, String search) { if (null == s0) { return ""; } int i = s0.indexOf(search); if (i == -1) { return ""; } return s0.substring(0, i); } }