链接:
https://www.nowcoder.com/test/question/done?tid=6726315&qid=26130#summary
来源:牛客网
来源:牛客网
考虑下面这个简单的例子,让我们看看reflection是如何工作的。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
import java.lang.reflect.*;
public
class
DumpMethods{
public
static
void
main(String[] args) {
try
{
Class c=Class.forName(args[0]);
Method m[]=c.getDeclaredMethods();
for
(
int
i = 0; i < m.length; i++) {
System.out.println(m[i].toString());
}
}
catch
(Throwable e) {
System.err.println(e);
}
}
}
|
其中"c.getDeclaredMethods"的作用是:
取得类的所有方法对象