黑马程序员技术交流社区

标题: 练习 单例设计模式 懒汉式 [打印本页]

作者: fmi110    时间: 2015-10-2 22:00
标题: 练习 单例设计模式 懒汉式
a

  1. public class T22 {

  2.         /**
  3.          * 懒汉式
  4.          */
  5.         public static void main(String[] args) {

  6.         }
  7. }
  8. class Singleton{
  9.         private Singleton(){};
  10.         private static Singleton s = null;
  11.         public static Singleton getInstance(){
  12.                 if(s==null){
  13.                         synchronized(Singleton.class){
  14.                                 if(s==null)
  15.                                         s = new Singleton();
  16.                         }
  17.                 }
  18.                 return s;
  19.         }
  20. }
复制代码







欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2