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 閱讀(1660) 評論(2)  編輯  收藏 所屬分類: java

          評論

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

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

          主站蜘蛛池模板: 南昌县| 翼城县| 新巴尔虎右旗| 青冈县| 当涂县| 新平| 天水市| 溧水县| 瓦房店市| 新余市| 天祝| 河西区| 长治县| 西青区| 扶沟县| 高要市| 喀喇沁旗| 绥化市| 阜平县| 都兰县| 台中市| 鄂托克前旗| 醴陵市| 上蔡县| 左权县| 米林县| 南昌县| 女性| 钦州市| 双辽市| 沙洋县| 灵石县| 栖霞市| 奎屯市| 芦溪县| 会昌县| 曲水县| 维西| 武邑县| 庐江县| 淄博市|