Java: pass in copy of "this"?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/869033/how-do-i-copy-an-object-in-java">How do I copy an object in Java?</a>  </p>
</blockquote>



<p>I've got a function in my class <code>Claus</code> which calls a function to accept type <code>Claus</code>. I'm currently passing in <code>this</code> as the argument, however it's editing the current instance of the class which I don't want it to do. Instead, I'd like it to clone the current instance of the class and edit that, keeping the copies separate. How can I do that?</p>

<p><em><strong>EDIT</em></strong></p>

<p>Perhaps I should have clarified my question a little further...</p>

<p>I've got an object which is inside another object.. e.g <code>Claus</code> and <code>floss</code>. I've been reading up on <code>shallow copy</code> vs <code>deep copy</code> and I think I've got <code>Claus</code> copying correctly. I'm doing it like so...</p>

<pre><code>public Claus(Claus g){
    cla = new Floss(g.getFloss());
            //irrelevant other variables...
    p = g.getP();
    c = g.getC();
}
</code></pre>

<p>However, the function within <code>Claus</code> which I'm declaring in the constructor the exact same way.. that is....</p>

<pre><code> cla = new Floss(g.getFloss());
</code></pre>

<p>Where cla = the <code>Floss</code> variable and g = <code>Claus</code> which is being passed into the Constructor. The <code>Floss</code> object doesn't seem to be creating a deep copy like it should. Why is this happening?</p>
