一段动态获得和执行方法的代码
来源:互联网 发布:C语言node 编辑:程序博客网 时间:2024/05/17 00:10
/**
* Override to run the test and assert its state.
* @exception Throwable if any exception is thrown
*/
protected void runTest() throws Throwable {
assertNotNull(fName);
Method runMethod= null;
try {
// use getMethod to get all public inherited
// methods. getDeclaredMethods returns all
// methods of this class but excludes the
// inherited ones.
runMethod= getClass().getMethod(fName, null);
} catch (NoSuchMethodException e) {
fail("Method /""+fName+"/" not found");
}
if (!Modifier.isPublic(runMethod.getModifiers())) {
fail("Method /""+fName+"/" should be public");
}
try {
runMethod.invoke(this, new Class[0]);
}
catch (InvocationTargetException e) {
e.fillInStackTrace();
throw e.getTargetException();
}
catch (IllegalAccessException e) {
e.fillInStackTrace();
throw e;
}
}
在看到这段代码之前,根本就没有想到Class会有getMethod这个方法,更没有想到会这么用,而且用得如此之妙。
- 一段动态获得和执行方法的代码
- delphi如何获得一段代码执行消耗的时间
- Java获得一段代码运行时间的方法和线程延时
- java中动态执行一段代码
- 一段获得网卡地址的代码
- 一段获得当前日期的JAVA代码
- C++获得一段代码的运行时间
- JQuery动态执行javascript代码的方法
- java计算一段代码执行的时间
- 周期性循环执行一段代码的实现
- 如何用VB写一段代码获得Excel文件中紀錄行的行数和列数?
- 在main函数执行之前和之后执行一段代码
- mach_absolute_time 快速容易的方法来检测一段ios 代码执行的效率函数
- java设置一段代码执行的超时时间的简单方法
- 一段动态滚动公告栏的js代码
- 保存一段ASP动态包含的代码
- 一段不错的代码,动态效果
- C# 获得当前目录和执行目录的一些方法
- EAServer Web Service Using PowerBuilder Component and Client
- Gmail Invitation
- 每个开发人员现在应该下载的十种必备工具
- 也说就业
- phpBB2的一种简单整合方案
- 一段动态获得和执行方法的代码
- Eclipse 3 + Lomboz 3 + Tomcat 5 (四)修订和补遗
- 世界编程大赛一等奖作品!!! [97']
- 网页加密JS代码
- 模拟多级表头的分组统计
- 特殊用途的IP地址介绍 zz
- 图像格式
- It is my pass
- 10月12,,我的smurf程序,,