1. /** 
  2. * 单例模式 
  3. */ 
  4. public class TestSingleton{ 
  5.     //私有化Constructor 
  6.     private TestSingleton(){ 
  7.         System.out.println("Singleton"); 
  8.         } 
  9.         //延迟加载对象 
  10.     private static class InnerClass{ 
  11.          private static TestSingleton instance = new TestSingleton(); 
  12.          
  13.         } 
  14. //不要出现同步的情况
  15.     public static TestSingleton getInstance(){ 
  16.         return InnerClass.instance; 
  17.         } 
  18.     }