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

论坛 期权论坛 脚本     
匿名技术用户   2021-1-3 13:28   264   0
 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);  
     }  
 }  
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP