标签:调用 return code blog private enum on() ret instance
public class EnumSingleton{ private EnumSingleton(){} public static EnumSingleton getInstance(){ return Singleton.INSTANCE.getInstance(); } private static enum Singleton{ INSTANCE; private EnumSingleton singleton; //JVM会保证此方法绝对只调用一次 private Singleton(){ singleton = new EnumSingleton(); } public EnumSingleton getInstance(){ return singleton; } } }
用枚举进行单例
标签:调用 return code blog private enum on() ret instance
原文地址:http://www.cnblogs.com/sishengchao/p/6418467.html