Let's say I have class A
public class A {
private int field1;
private String field2;
...
}
I create a new instance of A, then a second instance of A:
A a1 = new A();
A a2 = new A();
Is there any simple way (reflection or so) for copying fields from a2to a1without assigning an instance a2to a1(I don't want to change the instance link a1, only the values of its fields)? I know that I can do it manually in some method, but if there are many fields, then this is not practical.
I thought, is there any way to reflect?
Does anyone have experience?
source
share