您的位置:首页 > 编程语言 > Java开发

java 循环打印出某对象所在类的类名和方法

2009-11-09 15:25 435 查看
java 循环打印出某对象所在类的类名和方法

public class A {

public void b(){}
public void c(){}
public void d(){}
public void e(){}
}
import java.lang.reflect.*;
public class StaticTest {

public static void test(Object obj)
{
Class myclass = obj.getClass();
//System.out.println(myclass.getName());

Method[] mymethods = myclass.getDeclaredMethods();
int n = mymethods.length;
for(int i=0; i<n; i++)
{
System.out.println("类名:"+myclass.getName()+"; 方法名:"+mymethods[i].getName());
}
}

public static void main(String args[]){
A a = new A();
test(a);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐