public class NetWork {
private static Retrofit retrofit;
static {
retrofit = new Retrofit.Builder()
.client(builder.build())
.baseUrl("...")
.build();
}
private NetWork() {}
private static HomeApi homeApi;
public static HomeApi homeApi() {
if (homeApi == null) {
homeApi = retrofit.create(HomeApi.class);
}
return homeApi;
}
}
这样写会出现因为内存不足导致retrofit和homeApi两个对象一起被回收。而在此调用NetWork.homeApi()和导致的空指针吗?