彩虹天堂
          技術源于生活
          posts - 0,  comments - 2,  trackbacks - 0

          這個Bob Lee可是相當不簡單的說……

          他寫的一個Singleton模式的寫法前不久還得到了OnJava編輯的推薦呢:

          代碼
          1. public class Singleton {   
          2.   
          3.   static class SingletonHolder {   
          4.     static Singleton instance = new Singleton();   
          5.   }   
          6.   
          7.   public static Singleton getInstance() {   
          8.     return SingletonHolder.instance;   
          9.   }   
          10.   
          11. }  

          在加載singleton時并不加載它的內部類SingletonHolder,而在調用getInstance()時調用SingletonHolder時才加載SingletonHolder,從而調用singleton的構造函數,實力化singleton,從而達到lazy loading的效果。

          posted on 2008-05-05 22:13 bcterry 閱讀(421) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          留言簿

          文章檔案

          搜索

          •  

          最新評論

          主站蜘蛛池模板: 东阳市| 瓮安县| 德阳市| 新宁县| 许昌县| 古浪县| 诏安县| 高要市| 临猗县| 台州市| 远安县| 阳江市| 宜君县| 清镇市| 上林县| 博爱县| 宁国市| 房产| 自治县| 济南市| 科尔| 扶风县| 溧阳市| 阿图什市| 雷山县| 石狮市| 卓尼县| 德安县| 安塞县| 祁门县| 昭通市| 锡林浩特市| 江山市| 莒南县| 敦煌市| 巩留县| 白银市| 临夏市| 乐山市| 吉隆县| 康马县|