展开全部
import java.lang.reflect.Method;
public class Test {
public static void main(String[] args) {
String a = "testa";
String b = "testb";
call(a);
call(b, "hello");
}
private static void call(String methodName) {
try {
Method m = Test.class.getDeclaredMethod(methodName);
m.invoke(Test.class);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void call(String methodName, String param) {
try {
Method m = Test.class.getDeclaredMethod(methodName, String.class);
m.invoke(Test.class, param);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void testa() {
System.out.println("无参数");
}
public static void testb(String c) {
System.out.println(c);
}
}
试试这个可以不e69da5e887aa3231313335323631343130323136353331333337383330。
如果解决了您的问题请采纳!
如果未解决请继续追问