title: Create new Object from Returned Method Object from in Java
body: <p>Hi All hope you can help.</p>
  
  <p>I have a method of which returns a custom object of mine.
  This object contain an ArrayList and Strings.</p>
  
  <p>I want to create a new object of the same type that is returned from the method, which contains the same information that is returned.</p>
  
  <p>My question is, can I just create a new instance of this Object as per below?</p>
  
  <pre><code>public received_data_object XmlresponseParse(String Response) { 
      received_data_object received_data_object_instance = new  received_data_object();
  
      //Process some XML and add the item to the list.
      received_data_object_instance.addTo_List("SomeText");
  
      return received_data_object_instance;
  }
  </code></pre>
  
  <p>Then from the calling classes method , can I just say:</p>
  
  <pre><code>received_data_object received_data_object_otherInstance = new received_data_object();
  received_data_object_otherInstance = XmlresponseParse("SomeXMLString");
  </code></pre>
  
  <p>What I'm concerned about is, am I actually creating a new instance of the object, or am I passing the new object a reference to the object returned and so both will now be 'linked'?</p>
  
  <p>Is it best to just create my new object and then access the getters in the returned object and copy the values over to the new object?</p>
  
  <p>I'm concerned, because everything says you should detach your code from methods in classes like this but at the same time, everything seems to copy by reference to the original object.</p>
  
  <p>Thanks in advance. </p>