title: Change "linked" references to objects in java
body: <p>I am currently implementing a Vehicle Routing algorithm (the Savings heuristic). Here I have a node class consisting of three references:</p>
  <ol>
  <li>a node's predecessor in a tour (being a reference to another node)</li>
  <li>a node's successor (being a reference to another node)</li>
  <li>a tour class</li>
  </ol>
  <pre><code>class Node{
   Node pred;
   Node succ;
   Tour t;
  }
  
  class Tour{
   // Some data
  }
  </code></pre>
  <p>Throughout the code I want to change the tour reference in the following manner:</p>
  <pre><code>
  Node a = new Node();
  a.t = new Tour();
  Node b = new Node();
  b.pred = a;
  b.t = b.pred.t; // the tour of b is the same as of a, and a reference
  a.succ = b;
  
  // ... some more stuff
  
  Node c = new Node();
  c.t = new Tour();
  c.pred = a;
  a.succ = c;
  a.t = c.t; // &quot;adds&quot; a to the tour of c. Changes the reference to t in a and c, but not in b :(
  </code></pre>
  <p>After running the last line of code, the tour of b still points to the original tour of a (it remains in the memory). I would have assumed that, since it is a reference from the beginning, it now points to c.t</p>
  <p>Is there any chance of achieving what I desire without manually updating the references of all of a's successors?</p>
  <p>Thank you very much in advance!</p>