单例模式之懒汉式


//单例模式之懒汉式
public class Singleton {
    private Singleton() {
        // TODO Auto-generated constructor stub
    }

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

猜你喜欢

转载自blog.csdn.net/wwzheng16/article/details/80978600