Java 静态内部类的写法

public class HttpMethods {

 //在访问HttpMethods时创建单例
    private static class SingletonHolder{
        private static final HttpMethods INSTANCE = new HttpMethods();
    }

    //获取单例
    public static HttpMethods getInstance(){
        return SingletonHolder.INSTANCE;
    }
}

猜你喜欢

转载自blog.csdn.net/wolfking0608/article/details/83542247