I have a class X:
public class X implements Cloneable {
private int a;
private int b;
@Override
public X clone() throws CloneNotSupportedException {
return (X) super.clone();
}
}
I want to remember its initial state. Therefore get his clone:
try {
old = new X();
old = x.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
x - an object of class X, a and b installed. For example i do with old:
old.setA(7)
How do I now compare the old and the new object, find out whether there were changes. I do so but does not work:
//if object is changed
if (!old.equals(x)){
}
How to check the object has changed or not?