博客
关于我
2-单例模式 - 创建型模式
阅读量:399 次
发布时间:2019-03-05

本文共 1085 字,大约阅读时间需要 3 分钟。

??????

????????????????????????????????????????????????????????????????????

?????????????

public class SingleObject {        private static SingleObject instance = new SingleObject();        private SingleObject() {        }        public static SingleObject getInstance() {            return instance;        }        public void showMessage() {            System.out.println("?????????" + instance);        }    }

?????????????

public class SingletonPatternDemo {        public static void main(String[] args) {            for (int i = 0; i < 3; i++) {                SingleObject instance = SingleObject.getInstance();                instance.showMessage();            }        }    }

?????????????????

com.freedom.pattern.singleton.SingleObject@47089e5f  com.freedom.pattern.singleton.SingleObject@47089e5f  com.freedom.pattern.singleton.SingleObject@47089e5f

???????

???????????????

  • ???????????
  • ???????????public constructor???????????new?????
  • ?????????????????????????????????

????????????????????????????????????????????????

????

?????????????????????

转载地址:http://tphwz.baihongyu.com/

你可能感兴趣的文章
nodejs系列之express
查看>>
nodejs系列之Koa2
查看>>
Nodejs连接mysql
查看>>
nodejs连接mysql
查看>>
NodeJs连接Oracle数据库
查看>>
nodejs配置express服务器,运行自动打开浏览器
查看>>
Nodemon 深入解析与使用
查看>>
node不是内部命令时配置node环境变量
查看>>
node中fs模块之文件操作
查看>>
Node中同步与异步的方式读取文件
查看>>
Node中的Http模块和Url模块的使用
查看>>
Node中自启动工具supervisor的使用
查看>>
Node入门之创建第一个HelloNode
查看>>
node全局对象 文件系统
查看>>
Node出错导致运行崩溃的解决方案
查看>>
Node响应中文时解决乱码问题
查看>>
node基础(二)_模块以及处理乱码问题
查看>>
node安装及配置之windows版
查看>>
Node实现小爬虫
查看>>
Node提示:error code Z_BUF_ERROR,error error -5,error zlib:unexpected end of file
查看>>