Is there a generic utility in Java to check equality of a shallow copy? In the given example how do verify the shallow copy without of course rolling out my own implementation of equals()
public class ClonableExample {
public static class ClonableObject implements Cloneable, Serializable {
@Override public ClonableObject clone() throws CloneNotSupportedException {return (ClonableObject) super.clone();}
}
public static void main(String[] args) throws CloneNotSupportedException {
ClonableObject b = new ClonableObject();
System.out.println(b != b.clone());
System.out.println(b.equals(b.clone())); // Reference check fails
System.out.println(Objects.equals(b, b.clone())); // Nothing fancy but still a reference check that fails
System.out.println(Objects.deepEquals(b, b.clone())); // Reference check + Arrays.equals checks both of which fail
}
}
Open to 3rd party libraries if not available in core java