DESKTOP-7HC873M_20200905-李宗宝

问题

饿汉模式

public final class Earth {
    
    private static final Earth EARTH = new Earth();
    
    private Earth() {
        super();
    }
    public static Earth getInstance() {
        return EARTH ;
    }
}

懒汉模式

public final class Moon {
    
    private static Moon single ;
    
    private Moon() {
        super();
    }
    public static Moon getInstance() {
        if( single == null ) { 
            single = new Moon();
        }
        return single ;
    }
}

心得

这次考试真受打击了!!!

标签

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