代码
public class RetrofitUtil {
private static RetrofitUtil instance;
private Retrofit mRetrofit;
public static RetrofitUtil getInstance() {
if (instance==null) {
instance=new RetrofitUtil();
}
return instance;
}
public RetrofitUtil() {
mRetrofit=new Retrofit.Builder()
.baseUrl(GlobalConstant.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.client(OkHttpUtil.okHttpClient)
.build();
}
public <T> T create(Class<T> cls){
T t = mRetrofit.create(cls);
return t;
}
}
网友评论