日期:2014-05-20 浏览次数:20705 次
public static void main(String[] args) { try { String classPathName="t1.MyClass2"; String methodName="getValue"; Class c = Class.forName(classPathName); Constructor[] constructor = c.getConstructors(); Object myClass = constructor[0].newInstance(null); Method mthod = c.getDeclaredMethod(methodName, null); Object obj = mthod.invoke(myClass, null); System.out.println(obj); } catch (Exception e) { e.printStackTrace(); } }