java 单例模式

时间:2015-05-11 10:28:40   收藏:0   阅读:125

复习下单例模式 我擦今天上网看了下 单例整理的好多啊 自己就跟着敲一遍 顺便说下自己的理解。

单例第一种:

 1 public class Singleton {
 2     private static Singleton instance;
 3     private Singleton (){}
 4 
 5     public static Singleton getInstance() {
 6     if (instance == null) {
 7         instance = new Singleton();
 8     }
 9     return instance;
10     }
11 }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!