1)阅读HashMap.java的代码。在第 762 行,注释说子类覆盖它以改变 put 方法的行为。但是,函数void addEntry(int,K,V,int)是私有函数。它如何被子类覆盖?
/**
758 * Adds a new entry with the specified key, value and hash code to
759 * the specified bucket. It is the responsibility of this
760 * method to resize the table if appropriate.
761 *
762 * Subclass overrides this to alter the behavior of put method.
763 */
764 void addEntry(int hash, K key, V value, int bucketIndex) {
765 Entry<K,V> e = table[bucketIndex];
766 table[bucketIndex] = new Entry<>(hash, key, value, e);
767 if (size++ >= threshold)
768 resize(2 * table.length);
2) 在第 746 行和第 753 行,recordAccess和recordRemoval这两个函数保持为空。那么子类如何覆盖这两个函数呢?
static class Entry<K,V> implements Map.Entry<K,V> {
688 final K key;
689 V value;
690 Entry<K,V> next;
691 final int hash;
...
/**
742 * This method is invoked whenever the value in an entry is
743 * overwritten by an invocation of put(k,v) for a key k that's already
744 * in the HashMap.
745 */
746 void recordAccess(HashMap<K,V> m) {
747 }
748
749 /**
750 * This method is invoked whenever the entry is
751 * removed from the table.
752 */
753 void recordRemoval(HashMap<K,V> m) {
754 }
755 }