Is there a generic way to achieve copying an existing object into another?
Assume MyObj
has an id
and name
fields. Like this:
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 for each field
do something as following:
myObj_2.copyFrom(myObj_1)
so that they are different instances, but have equal properties.