反射问题

来源:互联网 发布:淘宝找不到自己的品牌 编辑:程序博客网 时间:2024/06/05 03:13
链接: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.*;
publicclass DumpMethods{
    publicstatic void main(String[] args) {
        try{
            Class c=Class.forName(args[0]);
            Method m[]=c.getDeclaredMethods();
            for(inti = 0; i < m.length; i++) {
                System.out.println(m[i].toString());
            }
        catch(Throwable e) {
            System.err.println(e);
        }
    }
}

其中"c.getDeclaredMethods"的作用是:

取得类的所有方法对象



0 0
原创粉丝点击