The question is about static methods Objects.deepEquals
class (since Java 7
):
public static boolean deepEquals(Object a, Object b) {
if (a == b)
return true;
else if (a == null || b == null)
return false;
else
return Arrays.deepEquals0(a, b);
}
As it said in javadoc
of this method:
Returns true if the arguments are deeply equal to each other and false otherwise.
What I do not understand: where is the depth of comparison? As we can see inside its implementation it just does references comparison, and inside Arrays.deepEquals0(a, b)
for simple Object
and Object
arguments it invokes
just: eq = e1.equals(e2);
. So in what kind of sense two objects are deeply equal?
The comparison would be deep, if you passed Array objects.
Non-array objects will not be evaluated deeper than what you get with equals
.
So the depth isn't relevant in your case :
Two null values are deeply equal. If both arguments are arrays, the algorithm in Arrays.deepEquals is used to determine equality. Otherwise, equality is determined by using the equals method of the first argument.
Quoted from :
Object.deepEquals
You can refer: Your's Deeply - Why Arrays.deepEquals When We Have Arrays.equals
Arrays.deepEquals looks really deep
From the source, we could understand that Arrays.deepEquals
- Loops through the input arrays, gets each pair
- Analyses the type of each pair
- Delegates the equal deciding logic to one of the overloaded Arrays.equals if they are one of the primitive arrays
- Delegates recursively to Arrays.deepEquals if it is an Object array
- Calls the respective object’s equals, for any other object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With