Thursday, 8 August 2013

copying objects with data fields

copying objects with data fields

I need to copy all content of class object to new class object. I don't
need to copy references to data, because in that case if I change fields
in object a2 those data will be changed in object a2.
public class Msg {
String Info="";
HashMap fld = new HashMap();
public void Assign(Msg value)
{
Info = value.Infol;
fld = value.fld;
}
}
a1 = new Msg();
a1.Info="111";
a1.fld.put("1","111");
a2 = new Msg();
a2.Assign(a1);
How to realise function Assign?

No comments:

Post a Comment