`

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

阅读更多
 public class A {  
       
     public void b(){}  
     public void c(){}  
     public void d(){}  
     public void e(){}  
 }  
 

 

import java.lang.reflect.Method;  
 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);  
     }  
 }  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics