1. 程式人生 > >最簡單好用安全的單例模式實現

最簡單好用安全的單例模式實現

使用內部類實現 

package com.zz.amqp1.multithread;

/**
 * Description: 最簡單好用的單例
 * User: zhouzhou
 * Date: 2018-11-05
 * Time: 15:50
 */
public class InnerSingleton {
    
    private static class SingletonInstance {
        private static  SingletonInstance singletonInstance = new SingletonInstance();
    }
    
    private SingletonInstance getSingleton(){
        return  SingletonInstance.singletonInstance;
    }
}