title: Why can't I use method return as a pointer in Java?
body: <p>Solved, thanks. I actually added head.next to my head.child's last node, so the next run of lastNode returned different pointer. </p>
  
  <p>In the following code, the commented code gave different result, why?</p>
  
  <p>I was expecting the same behavior. </p>
  
  <pre><code>            Node p = lastNode(head.child); //Define a extra pointer
              p.next = head.next;
              if(head.next!=null) head.next.prev = p;
  </code></pre>
  
  <pre><code>            //lastNode(head.child).next = head.next; // Not Working
              //head.next.prev = lastNode(head.child);
  </code></pre>