Is there a general way to copy an existing object to another?
Suppose MyObj has id and name fields. Like this:
MyObj myObj_1 = new MyObj(1, "Name 1"); MyObj myObj_2 = new MyObj(2, "Name 2");
Instead
myObj_2.setName(myObj_1.getName()) // etc for each field
do the following:
myObj_2.copyFrom(myObj_1)
so that they are different instances, but have equal properties.
java
Eugenep
source share