public class RetrofitManager { private static final String BASE_URL = "http://www.zhaoapi.cn/"; private static Retrofit retrofit; private static final class SINGLE_INSTANCE { private static final RetrofitManager instance = new RetrofitManager(); } public static RetrofitManager getInstance() { return SINGLE_INSTANCE.instance; } private RetrofitManager() { retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .client(new OkHttpClient.Builder().build()) .addConverterFactory(GsonConverterFactory.create()) .build(); } public <T> T create(Class<T> clazz) { return retrofit.create(clazz); } }
懒汉单例
最新推荐文章于 2022-10-31 21:53:47 发布