package com.stuty.singleton;

public class NbSingleton {
    private NbSingleton() {
    }
    public static NbSingleton getInstance(){
        return ContainerHolder.HOLDER.instance;
    }
    private enum ContainerHolder{
        HOLDER;
        private NbSingleton instance;
        ContainerHolder(){
            instance=new NbSingleton();
        }
    }
    public static void main(String[] args) {
        NbSingleton instance = NbSingleton.getInstance();
        System.out.println(instance);
        NbSingleton instance2 = NbSingleton.getInstance();
        System.out.println(instance2);
    }
}

java 单例 无视反射和序列化攻击

 

相关文章:

  • 2021-06-06
  • 2021-12-29
  • 2022-12-23
  • 2021-06-27
  • 2021-08-19
  • 2021-09-09
  • 2021-04-16
猜你喜欢
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
  • 2021-05-26
相关资源
相似解决方案