title: Why does a sub-class class of a class have to be static in order to initialize the sub-class in the constructor of the class?
body: <p>So, the question is more or less as I wrote.
  I understand that it's probably not clear at all so I'll give an example.</p>
  
  <p>I have class Tree and in it there is the class Node, and the empty constructor of Tree is written:</p>
  
  <pre><code>public class RBTree {
      private RBNode head;
  
      public RBTree(RBNode head,RBTree leftT,RBTree rightT){
          this.head=head;
          this.head.leftT.head.father = head;
          this.head.rightT.head.father = head;
      }
  
      public RBTree(RBNode head){
          this(head,new RBTree(),new RBTree());
      }
  
      public RBTree(){
          this(new RBNode(),null,null);
      }  
  
      public class RBNode{
          private int value;
          private boolean isBlack;
          private RBNode father;
          private RBTree leftT;
          private RBTree rightT;
      }
  }
  </code></pre>
  
  <p>Eclipse gives me the error: "No enclosing instance of type RBTree is available due to some intermediate constructor invocation" for the "new RBTree()" in the empty constructor.
  However, if I change the RBNode to be a static class, there is no problem.</p>
  
  <p>So why is it working when the class is static.</p>
  
  <p>BTW, I found an easy solution for the cunstructor:</p>
  
  <pre><code>public RBTree(){
      this.head = new RBNode();
  }
  </code></pre>
  
  <p>So, I have no idea what is the problem in the first piece of code.</p>