博客
关于我
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/

你可能感兴趣的文章
python函数编写_[零基础学python]传说中的函数编写条规
查看>>
Python+selenium —— UI自动化之鼠标操作
查看>>
python函数注释,参数后面加冒号:,函数后面的箭头→是什么?
查看>>
Python+Selenium+Threading进行兼容性测试
查看>>
Python+selenium+unittest的GUI自动化框架实现
查看>>
python函数拟合不规则曲线_Python计算&绘图——曲线拟合问题(转)
查看>>
python函数定义的基本格式_零基础学python-2.19 定义函数、调用函数与默认参数
查看>>
Python+Selenium之数据驱动测试的实现
查看>>
python函数定义与使用+返回值简解
查看>>
Python+Selenium登录
查看>>
Python日期时间模块
查看>>
Python函数合集:足足68个内置函数请收好!
查看>>
Python+Selenium自动化测试项目实战
查看>>
Python+Selenium自动化测试项目实战【建议收藏】
查看>>
Python+Selenium自动化测试:Page Object模式
查看>>
python+selenium进行cnblog的自动化登录测试
查看>>
Python函数只返回第一个值而不是数据框
查看>>
Python+SQL实战:京东用户行为数据分析案例解析(上)
查看>>
Python+SQL实战:京东用户行为数据分析案例解析(下)
查看>>
PYTHON+Twisted+sqlanydb=ABORT()
查看>>