title: Java: Invalidate a data structure by modifying the object passed as an argument
body: <p>I'm working on a Java generic implementation of AVL trees (the source code is at <a href="https://github.com/diningphil/AvlTreeJava" rel="nofollow">https://github.com/diningphil/AvlTreeJava</a>), and I've came across a specific problem: if I pass the <em>insert</em> method an argument <em>T key</em>, and then modify the fields of <em>key</em> after insertion, the data structure is corrupted. </p>
  
  <p>How can I avoid this? Can I pass an object requiring that it is not modifiable afterwards by the user but by the implementation of my avl trees?</p>
  
  <p>Thanks in advance</p>