Search code examples
javahashmap

Trying to instantiate HashMap.Node in Java


Java HashMap class has a static nested class Node

static class Node<K,V> implements Map.Entry<K,V>

I was trying to instantiate that Node class, but it seemed like I can't get it done as IDEA couldn't find any suitable option, as shown in screen shot below,

enter image description here

anyone here can enlignten me about this?

Can this static nested class be instantiated, if so, how?


Solution

  • HashMap.Node is declared with package private visibility (the default visibility if public, private or protected is not used).

        static class Node<K,V> implements Map.Entry<K,V> {
    

    This means that the class is only visible to classes in the same package.

    See this question for more details: What is the difference between public, protected, package-private and private in Java?