public class SingletonInner {
/* 私有构造方法,防止被实例化 */
private SingletonInner(){}
/* 此处使用一个内部类来维护单例 */
private static class SingletonFactory {
private static SingletonInner instance = new SingletonInner();
}
/* 获取实例 */
public static SingletonInner getInstance() {
return SingletonFactory.instance;
}
}
|