枚举方式创建单例对象
public class TestSingleton { private TestSingleton(){} public static TestSingleton getInstance(){ return SingletonEnum.INSTANCE.getTest(); } private enum SingletonEnum{ INSTANCE; private TestSingleton singleton = null; SingletonEnum(){ singleton = new TestSingleton(); } private TestSingleton getTest(){ return singleton; } } }