if we have two obejcts a and b of two classes A and B,
public class A{
String prop1;
String prop2;
String prop3;
String prop4;
public A(String prop1, String prop2, String prop3, String prop4) {
this.prop1 = prop1;
this.prop2 = prop2;
this.prop3 = prop3;
this.prop4 = prop4;
}
public A() {
}
//... setters and getters
}
public class B{
String prop2;
String prop3;
public B(String prop2, String prop3) {
this.prop1 = prop1;
this.prop2 = prop2;
this.prop3 = prop3;
this.prop4 = prop4;
}
public B() {
}
}
A a = new A("prop1","prop2","prop3","prop4");
B b = new B();
b.setProp3("p");
How can we copy not null properties from b to a ? in the example above, how we can copy prop3 which is not null and ignore prop2 which is null.