I have a question of how Map.Entry
used in Map implementation like HashMap
. Here is the code of how HashMap
is implemented in jdk8,
public interface Map<K, V> {
interface Entry<K, V> {
...
}
}
public class HashMap<K,V> extends AbstractMap<K,V>
implements Map<K,V>, Cloneable, Serializable {
static class Node<K,V> implements Map.Entry<K,V> {
public final K getKey() { return key; }
public final V getValue() { return value; }
}
transient Node<K,V>[] table;
}
I have 2 questions.
According to javadoc,
Map.Entry
is apublic static interface
, aspublic static interface Map.Entry<K,V>
. Why isstatic
missing in aboveinterface Entry<K, V>
? Does javadoc refer to Oracle jdk only?About the
static
keyword, my understanding is that internalMap.Entry
object,table
's element type, doesn't have reference to theHashMap
becauseNode
is astatic
class. Is thetable
variablestatic
? If thetable
isstatic
, then allHashMap
class objects will share the sametable
; and this doesn't sound right. Doesn't eachHashMap
object have distinct memory storage to host their contents?