-1

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?

Li Chen
  • 1
  • 1
  • What is the purpose to instantiate it? Maybe better to use HashMap put method to add something into the Map – Yurii Dec 19 '22 at 12:44
  • I know that HashMap.Node's constructor needs lots of arguments, but I just wonder whether it can be instantiated, grammatically – Li Chen Dec 19 '22 at 12:45
  • It is an internal class, that is used by HashMap to operate with values internally, encapsulated by design. – Yurii Dec 19 '22 at 12:51

1 Answers1

2

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?

rghome
  • 8,529
  • 8
  • 43
  • 62