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

你可能感兴趣的文章
proteus三输入与非门名字_proteus 元件名称对照表
查看>>
Protobuf - 语法、字段使用规则、注意事项
查看>>
protobuf —— 快速上手
查看>>
protobuf —— 认识和安装
查看>>
Protobuf 三个关键字required、optional、repeated的理解
查看>>
ProtoBuf 原理详解
查看>>
Protobuf 实例(java)
查看>>
ProtoBuf 实际应用(java)
查看>>