日期:2014-05-20 浏览次数:20650 次
import java.lang.reflect.Method;
public class Aaa {
public static void main(String[] args) {
String str = "getFuc1(1)";
String str1 = "getFuc2(1,2)";
Class c;
try {
c = Class.forName("Aaa");
Method m1 = c.getMethod("getFuc1", new Class[] {int.class});
Method m2 = c.getMethod("getFuc2", new Class[] {int.class,int.class});
m1.invoke(c, new Object[] {1});
m2.invoke(c, new Object[] {1,2});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void getFuc1(int i){
System.out.println(i+"获得函数1成功");
}
public static void getFuc2(int i,int j){
System.out.println(i+".."+j+"获得函数2成功");
}
}