HashMap Entry类的recordAccess()方法是空体

时间:2014-06-23 07:34:12

标签: java collections hashmap

API有这样的评论..

但是它做了什么?因为它有空身方法。

/**
 * This method is invoked whenever the value in an entry is
 * overwritten by an invocation of put(k,v) for a key k that's already
 * in the HashMap.
 */
void recordAccess(HashMap<K,V> m) {
}

3 个答案:

答案 0 :(得分:6)

存在被子类覆盖。访问记录时调用它。 LinkedHashMap子类重写此方法,并使用它将频繁访问的记录移动到链接列表的前面。

答案 1 :(得分:3)

Entry子类中的LinkedHashMap子类中有一个方法体(HashMap的子类)。该方法存在于基类Entry类中,以便能够在基类HashMap类中使用公共代码。但由于访问记录在HashMap s LinkedHashMap s中无效,因此该方法无法执行任何操作。

答案 2 :(得分:0)

在JDK7中,LinkedHashMap中没有put方法,但是覆盖了类Entry,这意味着在LinkedHashMap中放置元素会调用HashMap的put,但是使用LinkedHashMap的recordAccess