首页 > 其他 > 详细

单例模式

时间:2019-11-22 17:03:48      阅读:92      评论:0      收藏:0      [点我收藏+]

单例模式

手写单例模式

代码实现

package 剑指offer;

/**
 * @author WangXiaoeZhe
 * @Date: Created in 2019/11/22 16:01
 * @description:
 */

public class Singleton {

    /**
     * 饿汉式
     */

    private static Singleton instance = new Singleton();
    private Singleton(){}

    static Singleton getInstance() {
        return instance;
    }

    /**
     * 懒汉式
     */

    private static Singleton instance=null;
    private Singleton() {

    }
    static Singleton getInstance(){
        if (instance == null) {
            instance=new Singleton();
        }
        return instance;
    }

}

单例模式

原文:https://www.cnblogs.com/wuhen8866/p/11912161.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!