Java单例模式简单实现
2014-02-13 13:53
176 查看
代码
public class Singleton { private static Singleton singleton;//创建一个单例对象 public static Singleton getSingleton(){ if(singleton == null){//判断对象是否为空 singleton = new Singleton(); } return singleton; } }
public class Test { public static void main(String[] args) { Singleton s1 = Singleton.getSingleton(); Singleton s2 = Singleton.getSingleton(); System.out.println(s1 == s2); //输出true System.out.println(s1.equals(s2)); //输出true } }
相关文章推荐
- WebClient.DownloadFileAsync实现下载网络数据-简单的下载软件
- Python实现爬取知乎神回复简单爬虫代码分享
- php实现简单的用户注册,登录,修改个人信息接口
- 简单的实现页面登陆
- Silverlight学习笔记十八最简单的添加双击事件的实现方法
- C#实现简单获取扫码枪信息代码
- python实现登录函数,比较简单
- Jquery AJAX 简单实现前台后台互传数据
- 浅谈thinkphp5 instance 的简单实现
- 登录界面的JSP简单实现
- Opencv实现简单的人脸检测
- 实现简单的shell
- AJAX引擎(简单实现)
- videoview 实现简单播放器
- JS获取屏幕高度的简单实现代码
- php简单实现MVC
- 最简单的Rpc框架的实现
- 简单神经网络实现 03
- 简单工厂C++实现
- 常用排序算法简单实现