I have two objects of the same type. I want to create a method that can combine the properties of two objects and can return a single object.
For example: Consider a class ABC having 4 fields
Class ABC{
String name;
String id;
String salary;
String status;
}
Assume the first object
ABC[name=ZEE,id=2,salary=null,status=1]
and the second object
ABC[name=john,id=null,salary=12200,status=null]
I want to create a general method that can combine these two objects and can produce the result:
ABC[name=ZEE,id=2,salary=12200,status=1]
The method must take two parameters of the object type:
Object mergeObject(Object Obj1, Object Obj2){
}
Note. This property will have the first property of the object if both objects have a nonzero value for this property.
source
share