简单的单例模式
package com.demo.sw.test; public class HungerySingleton { private HungerySingleton(){ } private static HungerySingleton s = new HungerySingleton(); public static HungerySingleton getInstance(){ return s; } } package com.demo.sw.test; public class LazySingleton { private LazySingleton(){ } private static LazySingleton ls = null; public static LazySingleton getInstance(){ if(null == ls){ ls = new LazySingleton(); } return ls; } }