title: Deep clone of a class, that has static nested class
body: <p>I'am doing a task, in short - custom LinkedList. I need to override Object.clone to make deep copy of MyLinkedList, but I don't understand, do I need to clone both, mested and outer class? Here is the code:</p>
  
  <pre><code>public class MyLinkedList implements Cloneable {
  
      private Entry header;
      private int size;
  
      .....................
  
      @Override
      public Object clone() {
          MyLinkedList newObject = null;
          try {
              newObject = (MyLinkedList) super.clone();
              newObject.header = this.header.clone();
          } catch (CloneNotSupportedException e) {
              System.err.print("Clone not supported");
          }
          return newObject;
      }
  
      private static class Entry implements Cloneable {
          double data;
          Entry prev;
          Entry next;
  
          public Entry(double data, Entry next, Entry prev) {
              this.data = data;
              this.next = next;
              this.prev = prev;    
          }
  
          @Override
          public Entry clone() {
              Entry newObject = null;
              try {
                  newObject = (Entry) super.clone();
                  newObject.prev = this.prev.clone();
                  newObject.next = this.next.clone();
              } catch (CloneNotSupportedException e) {
                  System.err.print("Clone not supported");
              }
              return newObject;
          }
      }   
  }
  </code></pre>
  
  <p>When i try to clone MyLinkedList i get java.lang.StackOverflowError. What am I doing wrong?</p>