Merging two objects in Java

前端 未结 8 782
离开以前
离开以前 2020-12-15 23:25

I have two objects of same type.

Class A {
  String a;
  List b;
  int c;
}

A obj1 = new A();
A obj2 = new A();

obj1 => {a = \"hello\"; b = null; c = 10         


        
8条回答
  •  伪装坚强ぢ
    2020-12-15 23:54

    If you create getters and setters for the attributes, you can use the copyProperties method from Commons BeanUtils.

提交回复
热议问题