获取类实例
/** 时 代 J a v a - N o w J a v a . c o m 提供 **/ //package com.nowjava; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; public class Main { public static Object getClassInstance(String className, Class[] paramTypes, Object[] params) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Object obj = null; Class actionClassObj; actionClassObj = Class.forName(className); Constructor cons = actionClassObj.getConstructor(paramTypes); obj = cons.newInstance(params); return obj; } public static <T> T getClassInstance(String className, Class[] paramTypes, Object[] params, Class<T> c)/*from nowjava.com - 时代Java*/ throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Object obj = null; Class actionClassObj; actionClassObj = Class.forName(className); Constructor cons = actionClassObj.getConstructor(paramTypes); obj = cons.newInstance(params); return (T) obj; } public static Object getClassInstance(String className, Class[] paramTypes, Object[] params, ClassLoader customClassLoader) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,