2
public class MyCache {
AbstractMap<String, AbstractMap<String, Element>> cache = new TreeMap<String, AbstractMap<String,
Element>>();
public Boolean putElement(String targetNamespace, Element element) {
...
}
public void clear() {
cache.clear();
}
// is it better this way?
public void deepClear() {
for(AbstractMap<String, Element> innerMap : cache.values()) {
innerMap.clear();
}
cache.clear();
}
}
是否需要遍歷根映射的值並清除根中嵌套的所有映射,或者是否足以清除最外面的映射? 我的主要問題是,如果這兩種方法之間的JVM的內存消耗有任何區別?清除嵌套在Java中的地圖的好方法
使用'AbstractMap'的任何具體原因,爲什麼不直接使用'Map''interface'? – harsh 2013-04-26 07:58:13
不,這只是因爲我的IDE總是建議從java.util以外的其他包映射實現,如果我使用「Map」而不是「AbstractMap」。 – 2013-04-26 08:02:07