- /**
- * 单例模式
- */
- public class TestSingleton{
- //私有化Constructor
- private TestSingleton(){
- System.out.println("Singleton");
- }
- //延迟加载对象
- private static class InnerClass{
- private static TestSingleton instance = new TestSingleton();
- }
- //不要出现同步的情况
- public static TestSingleton getInstance(){
- return InnerClass.instance;
- }
- }