1. 程式人生 > >單例模式 建立型 設計模式(六)

單例模式 建立型 設計模式(六)

package singleton;
/**
* Created by noteless on 2018/10/11.
* Description:
*/
public class LazySingleton {
    private LazySingleton() {
    }
    private static volatile LazySingleton singleton = null;
        public static LazySingleton getInstance() {
        if (singleton == null) {
            
synchronized (LazySingleton.class) { if (singleton == null) { singleton = new LazySingleton(); } } } return singleton; } }