Objects.deepEquals 方法的含义
Meaning of Objects.deepEquals method
问题是关于静态方法的 Objects.deepEquals
class(因为 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);
}
如本方法javadoc
中所述:
Returns true if the arguments are deeply equal to each other and false
otherwise.
我不明白的是:比较的depth在哪里?正如我们在它的实现中看到的那样,它只是进行引用比较,在 Arrays.deepEquals0(a, b)
内部它调用简单的 Object
和 Object
参数
只是:eq = e1.equals(e2);
。那么在何种意义上两个对象深度相等?
如果传递 Array 对象,比较将是 deep。
Non-array 对象的评估不会比使用 equals
得到的更深入。
因此深度与您的情况无关:
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.
引自:
您可以参考: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
问题是关于静态方法的 Objects.deepEquals
class(因为 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);
}
如本方法javadoc
中所述:
Returns true if the arguments are deeply equal to each other and false otherwise.
我不明白的是:比较的depth在哪里?正如我们在它的实现中看到的那样,它只是进行引用比较,在 Arrays.deepEquals0(a, b)
内部它调用简单的 Object
和 Object
参数
只是:eq = e1.equals(e2);
。那么在何种意义上两个对象深度相等?
如果传递 Array 对象,比较将是 deep。
Non-array 对象的评估不会比使用 equals
得到的更深入。
因此深度与您的情况无关:
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.
引自:
您可以参考: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