HelloWorld 善戰者,求之于勢,不責于人;故能擇人而任勢。

          知止而后有定,定而后能靜,靜而后能安,安而后能慮,慮而后能得。物有本末,事有終始。知所先后,則近道矣。

            BlogJava :: 首頁 ::  :: 聯系 ::  :: 管理 ::
            167 隨筆 :: 1 文章 :: 40 評論 :: 0 Trackbacks

          如有個類
          class A {
              public native int add(int a, int b) ;
          }

          我們想要知道方法add的public , native 的關鍵字

          import java.lang.reflect.Method; class Test {
              public static void main(String args[]) {
                  Class[] clses = {int.class,int.class};
                  Method m = A.class.getDeclaredMethod("add", clses);
                 int modifers = m.getModifiers();
                  //1.判斷是否為native
                 modifers = modifers %512;
                 modifers = modifers >> 8;
                 if (modifers != 1) {
                      System.out.println("error");
                 }    
                  // 2....
              }
          } 根據java中的定義表,按位存放的標記,參考如下
          java.lang.reflect.Modifier
          public static final int ABSTRACT 1024
          public static final int FINAL 16
          public static final int INTERFACE 512
          public static final int NATIVE 256
          public static final int PRIVATE 2
          public static final int PROTECTED 4
          public static final int PUBLIC 1
          public static final int STATIC 8
          public static final int STRICT 2048
          public static final int SYNCHRONIZED 32
          public static final int TRANSIENT 128
          public static final int VOLATILE 64


          </script>

          posted on 2007-11-30 10:31 helloworld2008 閱讀(1658) 評論(2)  編輯  收藏 所屬分類: java

          評論

          # re: Java 判斷某個方法的public,native等標識 2007-11-30 20:30 oracle
          不錯啊  回復  更多評論
            

          # re: Java 判斷某個方法的public,native等標識 2008-06-15 17:15 asdf
          你舍近求遠啊?  回復  更多評論
            

          主站蜘蛛池模板: 贵溪市| 文登市| 常宁市| 灵川县| 青冈县| 崇信县| 新平| 西安市| 永川市| 定西市| 龙里县| 平安县| 黑水县| 亳州市| 通城县| 鹤壁市| 珲春市| 米脂县| 衡东县| 常熟市| 红原县| 朝阳市| 天峨县| 射阳县| 电白县| 阿克陶县| 惠州市| 中西区| 通化市| 定远县| 南华县| 通渭县| 勐海县| 石屏县| 融水| 巴青县| 衡东县| 新宁县| 甘孜县| 定陶县| 轮台县|