隨筆 - 154  文章 - 60  trackbacks - 0
          <2007年10月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          聲明:

          該blog是為了收集資料,認識朋友,學習、提高技術,所以本blog的內容除非聲明,否則一律為轉載!!

          感謝那些公開自己技術成果的高人們!!!

          支持開源,尊重他人的勞動!!

          常用鏈接

          留言簿(3)

          隨筆分類(148)

          隨筆檔案(143)

          收藏夾(2)

          其他

          學習(技術)

          觀察思考(非技術)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          /*
           有synthetic標記的field和method是class內部使用的,
           正常的源代碼里不會出現synthetic field。小穎編譯工具用的就是jad.
           所有反編譯工具都不能保證完全正確地反編譯class。所以你不能要求太多。
           下面我給大家介紹一下 synthetic
           下面的例子是最常見的 synthetic field
          */
          class parent{
           public void foo(){
            System.out.println("this is foo");
           }
           
           class inner{
            inner(){
             foo();
            }
           }
          }
          /*
           非static的inner class里面都會有一個this$0的字段保存它的父對象。編譯后的inner class 就像下面這樣:

          class parent$inner{
           synthetic parent this$0;
           parent$inner(parent this$0){
            this.this$0 = this$0;
            this$0.foo();
           }
          }

          所有父對象的非私有成員都通過 this$0來訪問。

          還有許多用到synthetic的地方。比如使用了 assert 關鍵字的class會有一個
          synthetic static boolean $assertionsDisabled 字段
          使用了assert的地方
          assert condition;
          在class里被編譯成
          if(!$assertionsDisabled && !condition){
           throw new AssertionError();
          }

          還有,在jvm里,所有class的私有成員都不允許在其他類里訪問,包括它的inner class。
          在java語言里inner class是可以訪問父類的私有成員的。在class里是用如下的方法實現的:

          class parent
          {
           private int value = 0;
           synthetic static int access$000(parent obj){
            return value;
           }
          }

          在inner class里通過access$000來訪問value字段。

          希望通過上面幾個例子,大家對synthetic 有所了解。
          */

          posted on 2007-10-19 11:07 lk 閱讀(839) 評論(0)  編輯  收藏 所屬分類: j2se
          主站蜘蛛池模板: 浮山县| 台南县| 孟津县| 武山县| SHOW| 大庆市| 潞西市| 九江县| 兴宁市| 伊金霍洛旗| 泸溪县| 巴里| 固始县| 通江县| 罗甸县| 凤庆县| 和政县| 突泉县| 荆门市| 高唐县| 黑山县| 平泉县| 阿坝| 凤山市| 湘阴县| 侯马市| 宣武区| 凌云县| 邢台县| 天等县| 二手房| 青铜峡市| 通江县| 厦门市| 兴安县| 中阳县| 洞头县| 广安市| 金秀| 崇文区| 全椒县|