单例模式

来源:互联网 发布:淘宝网广告形式 编辑:程序博客网 时间:2024/06/07 00:22
package com.kiloPhone.designmode;/** * 饿汉式 */class SingletonHungryType {private static SingletonHungryType instance = new SingletonHungryType();private SingletonHungryType() {}static SingletonHungryType getInstance() {return instance;}}/** * 懒汉式 */class SingletonLazyType {private static SingletonLazyType instance = null;private SingletonLazyType() {}static SingletonLazyType getInstance() {if (instance == null) {instance = new SingletonLazyType();}return instance;}}


原创粉丝点击