java 单例模式的几种创建方式
方式一 (私有静态内部类)
/**
* @desc java singleton class generate by private static internal class
*/
public class HookManagerHandler {
private HookManagerHandler() {
}
private static class MangerHandler {
private static HookManagerHandler hookManagerHandler = new HookManagerHandler();
}
public static HookManagerHandler getInstance() {
return MangerHandler.hookManagerHandler;
}
}
方式二(私有静态成员变量)
/**
* @desc a variable static final
*/
public final class HookManager {
private static final HookManager HMG = new HookManager();
public static HookManager get() {
return HMG;
}
}