public class MyClass{
public String elem1;
public int elem2;
public MyType elem3;
.................
}
MyClass object1=new MyClass();
MyClass object2=new MyClass();
object1.elem1=...
object1.elem2=...
...
object2.elem1=...
object2.elem2=null
.....
What I want is something like
object1.merge(object2);
where it will dynamically traverse all members on MyClass and run this on every member
if(object1.elem != object2.elem && object2.elem!=null)
object1.elem=object2.elem;
Is such a mechanism exist in Java?
use reflection.
go over fields of class. Psuedo:
and match the values. if they differ, then update the value.