码迷,mamicode.com
首页 > 其他好文 > 详细

单例模式

时间:2017-10-14 23:27:18      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:static   print   singleton   get   final   rgs   sys   单例模式   turn   

public class Singleton {
private static final Singleton instance = new Singleton();

private Singleton() {
}

public static Singleton getInstance() {
return instance;
}

public static void main(String[] args) {
Singleton instance1 = Singleton.getInstance();
Singleton instance2 = Singleton.getInstance();
System.out.println(instance1 == instance2);
}
}

单例模式

标签:static   print   singleton   get   final   rgs   sys   单例模式   turn   

原文地址:http://www.cnblogs.com/panning/p/7668881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!