DESKTOP-0FT47VC_20200907-罗贤丞

问题

饿汉式单例与懒汉式单例

解决

public final class HungryMan {
    private static final HungryMan HM = new HungryMan();

    private HungryMan() {
        super();
    }

    public static HungryMan getInstance() {
        return HM;
    }
}


public final class Idler {
    private static Idler idler;

    private Idler() {
        super();
    }

    public static Idler getInstance() {
        if (idler == null) {
            idler = new Idler();
        }
        return idler;
    }
}

吐槽

做题总是粗心大意,以后还得多加细心。天气很热,很难受。

标签

© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1