title: Circular Immutable Linked List in Java
body: <p>I have a simple Immutable Linked list class the following:</p>
  
  <pre><code>class Node&lt;T&gt; {
      final T val;
      final Node next;
      Node(T val, Node next) {
          this.val = val;
          this.next = next;
      }
  }
  </code></pre>
  
  <p>I would like to create an instance which  has itself as the next node, thereby creating a circular list.</p>
  
  <p>I obviously can't do <code>Node x = new Node&lt;&gt;(0, x)</code>, since <code>x</code> won't be defined by the time it should be passed to the constructor.</p>
  
  <p>Are there any tricks that'd allow me to create this without changing <code>Node</code>?</p>
  
  <p>For example, <a href="http://stackoverflow.com/a/25473855/205521">http://stackoverflow.com/a/25473855/205521</a> describes how to do something similar for lambda functions, that is a function which refers to itself (recursion). I, however, wasn't able to make it work for initialization.</p>