美文网首页
单例模式(Singleton)

单例模式(Singleton)

作者: KuDana | 来源:发表于2020-03-27 10:48 被阅读0次

单例模式(Singleton)

枚举单例

public enum Singleton {

    INSTANCE;

    public void m() {}

    public static void main(String[] args) {

        for(int i = 0; i<100; i++) {
            new Thread(()->{

                System.out.println(Singleton.INSTANCE.hashCode());

            }).start();

        }

   }

}

相关文章

网友评论

      本文标题:单例模式(Singleton)

      本文链接:https://www.haomeiwen.com/subject/bbfycftx.html