Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.lang.reflect.*;
  2.  
  3. /**
  4.  * 補充 Class cls=Class.forName("");//填入要使用或查詢的class name,例如java.lang.String
  5.  *
  6.  * Constructor ctorlist[] = cls.getDeclaredConstructors();//查出建構子
  7.  *
  8.  * Field fieldlist[] = cls.getDeclaredFields();//查出欄位
  9.  */
  10. public class DumpMethods {
  11.     public static void main(String args[]) {
  12.         try {
  13.             String str = "DumpMethods";
  14.             Class c = Class.forName(str);// 填入要使用或查詢的class
  15.                                             // name,例如java.lang.String
  16.             Method m[] = c.getDeclaredMethods();// 捉出此class中所有的方法
  17.             for (int i = 0; i < m.length; i++)
  18.                 System.out.println(m[i].toString());// 印出此class中所有的方法
  19.         } catch (Throwable e) {
  20.             System.err.println(e);
  21.         }
  22.     }
  23.  
  24.     public int getInt() {
  25.         return 1;
  26.     }
  27. }