加载中...

单例模式0

单例模式一种最常见的Java写法:


public class Singleton {
    private static Singleton inst<details>
    private Singleton() {}
    public synchronized static Singleton getInstance() {
        if (instance == null) {
            instance = new Singleton();
        }
        return instance;
    }
    public void singletonTest() {
        System.out.println("singletonTest is called.");
    }
}

posted @ 2022-09-05 23:33  biubidio  阅读(29)  评论(0)    收藏  举报