SingletonClass.java /** * 单例模式--静态内部类 * Author: SantosZhou. * Date: 2017/2/23 09:10. * Package: com.zhourl.hellossh.cases.singleton. */public class SingletonClass { /** * 私有化构造器 */ private SingletonClass() { }
/** * 单例模式--静态内部类 * Author: SantosZhou. * Date: 2017/2/23 09:10. * Package: com.zhourl.hellossh.cases.singleton. */ public class SingletonClass { /** * 私有化构造器 */ private SingletonClass() { } /** * 静态内部类--第一被引用是加载 */ private static class SingletonClassInstance { private static final SingletonClass instance = new SingletonClass(); } /** * 获取单例 * @return Singleton对象 */ public SingletonClass getInstance() { return SingletonClassInstance.instance; } }