title: How to extend an existing Tree (with children, but no parents) to a doubly linked tree?
body: <p>I have a Tree&lt;> class (legacy code, can't be changed), where each node consists of a label and a list of children:</p>
  
  <pre><code>public class Tree&lt;L&gt; implements Serializable, Comparable&lt;Tree&lt;L&gt;&gt;, Iterable&lt;Tree&lt;L&gt;&gt; {
      public Tree(L label, List&lt;Tree&lt;L&gt;&gt; children) {
          this.label = label;
          this.children = children;
      }
      ...
      // lots of methods, including the usual setters and getters
  }
  </code></pre>
  
  <p>Now, I want to write a class <code>DoublyLinkedTree&lt;L&gt; extends Tree&lt;L&gt;</code> where, in addition to the children, each node also has a parent pointer. Normally, I wouldn't try to do this, but the base <code>Tree&lt;&gt;</code> class already contains a lot of very useful methods (e.g. <code>getSubtrees()</code>, <code>getSubtreesAtDepth()</code>) which I do not want to rewrite.</p>
  
  <p>The trouble with extending the base class is that I want methods like <code>setChildren(List&lt;DoublyLinkedTree&lt;L&gt;&gt; children)</code>, which clash with the method <code>setChildren(List&lt;Tree&lt;L&gt;&gt; children)</code> in the base class.</p>
  
  <p>Is there an elegant way to write a doubly-linked tree class extending the <code>Tree&lt;&gt;</code> class? The base class is very ill-suited for methods that involve <em>upward</em> searches like <code>getGrandParent()</code>, <code>getAllAncestorLabels()</code>, etc.</p>
  
  <p>I am not expecting a readymade solution, but I feel that I am looking to solve the issue in a wrong way. Any guidance will be of immense help.</p>