单例模式
单例模式
手写单例模式
代码实现
package 剑指offer;
/**
 * @author WangXiaoeZhe
 * @Date: Created in 2019/11/22 16:01
 * @description:
 */
public class Singleton {
    /**
     * 饿汉式
     */
    private static Singleton instance = new Singleton();
    private Singleton(){}
    static Singleton getInstance() {
        return instance;
    }
    /**
     * 懒汉式
     */
    private static Singleton instance=null;
    private Singleton() {
    }
    static Singleton getInstance(){
        if (instance == null) {
            instance=new Singleton();
        }
        return instance;
    }
}
    人生若只如初见,浮沉繁华,慕然回首,不过过眼云烟。
我只在红尘中争渡,即便是一朵浪花,亦奋勇向前。
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号