我刚刚浏览了Ion的源代码,发现Ion使用静态HashMap static HashMap<String, Ion> instances = new HashMap<String, Ion>();
来存储Ion对象,并且调用Ion.with(context)
应该返回相同的实例,如代码所示(如果我错了,请纠正我)
public static Ion getDefault(Context context) {
return getInstance(context, "ion");
}
public static Ion getInstance(Context context, String name) {
if (context == null)
throw new NullPointerException("Can not pass null context in to retrieve ion instance");
Ion instance = instances.get(name);
if (instance == null)
instances.put(name, instance = new Ion(context, name));
return instance;
}
但是当我比较对象时,它返回false。谁能告诉我我错过了什么?
Log.d(TAG, String.valueOf( Ion.with(getApplicationContext()).equals(Ion.with(getApplicationContext())) ));
答案 0 :(得分:0)
public static LoadBuilder<Builders.Any.B> with(Context context) {
return getDefault(context).build(context);
}
public LoadBuilder<Builders.Any.B> build(Context context) {
return new IonRequestBuilder(ContextReference.fromContext(context), this);
}
它使用相同的Ion对象,但每次都返回新的构建器。