title: Java - Is it safe to do deepCopy of UUID field as this.uuid = original.getUUID()?
body: <p>For the following class, when I do deep copy, is it safe to write code as </p>
  
  <pre><code>this.id = original.getId();
  </code></pre>
  
  <p>In my test, it seems OK, as when I want to update the UUID field, I always assign it with a new UUID instance(I couldn't find any function which can modify an existing UUID instance). In this case, this copied one will never have side effect to original instance.</p>
  
  <pre><code>public class Container {
  
      private Type type;
      private UUID id;
      private Container c;
  
      // public constructors here
  
      protected Container(Container original, boolean deepCopy) {
          this.type = original.getType();
          this.id = original.getId();
          // for deep copy of id field, should I write as:
          // this.id = new UUID(original.getId().getMostSignificantBits(), original.getId().getLeastSignificantBits());
          if (original.getC() != null) {
              this.c = deepCopy ? original.getC().deepCopy() : original.getC();
          }
      }
  
      // getter and setter here
  
      public Container deepCopy() {
          return new Container(this, true);
      }
  
  }
  </code></pre>
  
  <p>However in the project I maintained now(Not created by me), I find the deep copy code is as this:</p>
  
  <pre><code>this.id = new UUID(original.getId().getMostSignificantBits(), original.getId().getLeastSignificantBits());
  </code></pre>
  
  <p>No doubt, this is a correct solution. </p>
  
  <p>My question is: is it safe to do this as </p>
  
  <pre><code>this.id = original.getId();
  </code></pre>
  
  <p>Maybe this is a stupid question, thanks for your time to help me.</p>