Copy object into another

Posted by EugeneP on Stack Overflow See other posts from Stack Overflow or by EugeneP
Published on 2010-03-29T09:23:55Z Indexed on 2010/03/29 9:33 UTC
Read the original article Hit count: 375

Filed under:

Is there an easy way how to achieve this:

MyObj : (id, name);


MyObj myObj_1 = new MyObj(1, "Name 1");

MyObj myObj_2 = new MyObj(2, "Name 2");

instead of

myObj_2.setName(myObj_1.getName()) etc

do something as following:

myObj_2.copyFrom(myObj_1)

so that they are different instances, but have equal properties.

© Stack Overflow or respective owner

Related posts about java