headfirsh设计模式——单件模式例子

"""
单件模式
"""
public class Singleton{
    private static Singleton uniqueInstance;

    private Singleton(){}
    public static Singleton getInstance(){
        if (uniqueInstance == null){
            uniqueInstance = new Singleton();
        }
        return uniqueInstance
    }
}

public class Singleton{
    private static Singleton uniqueInstance;

    private Singleton(){}

    public static synchronized Singleton getInstance(){
        if (uniqueInstance == null){
            uniqueInstance = new Singleton()
        }
        return uniqueInstance
    }
}


上一篇:Mysql各版本号的含义


下一篇:饿汉式和懒汉式实现单例模式