aio*_*obe 26
在java中,它可以通过反射api完成.
看看Class.getMethod(String methodName, Class... parameterTypes).
一个完整的例子(带有参数的非静态方法)将是:
import java.lang.reflect.*;
public class Test {
public String methodName(int i) {
return "Hello World: " + i;
}
public static void main(String... args) throws Exception {
Test t = new Test();
Method m = Test.class.getMethod("methodName", int.class);
String returnVal = (String) m.invoke(t, 5);
System.out.println(returnVal);
}
}
Run Code Online (Sandbox Code Playgroud)
哪个输出:
Hello World: 5
| 归档时间: |
|
| 查看次数: |
22996 次 |
| 最近记录: |