分析LinkedHashMap
LinkedHashMap是继承HashMap的一个子类,除了包含HashMap的方法外,还提供了removeEldestEntry方法,该方法在源码中实现:
protected boolean removeEldestEntry(Map.Entry<K,V> eldest) {
return false;
}
该方法好像没什么作用,先不要这么快急着下结论,让我们先看看该方法在哪里被调用了。
上源码:
void addEntry(int hash, K key, V value, int bucketIndex) {
super.addEntry(hash, key, value, bucketIndex);
// Remove eldest entry if instructed
Entry<K,V> eldest =