有人可以向我解释一下这段代码。我不完全理解这一点。它是为上传图像创建一个内存cashe .. 特别是,我想知道 * 1.什么是softReference * 2.什么是containsKey * 3. softReference是否存储在内存中 * 4.为什么Cashe是synchronizedMap(cache = Collections.synchronizedMap)
非常感谢
package com.androidhive.imagefromurl;
import java.lang.ref.SoftReference;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import android.graphics.Bitmap;
public class MemoryCache {
private Map<String, SoftReference<Bitmap>> cache=Collections.synchronizedMap(new HashMap<String, SoftReference<Bitmap>>());
public Bitmap get(String id){
if(!cache.containsKey(id))
return null;
SoftReference<Bitmap> ref=cache.get(id);
return ref.get();
}
public void put(String id, Bitmap bitmap){
cache.put(id, new SoftReference<Bitmap>(bitmap));
}
public void clear() {
cache.clear();
}
}