Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android Pair'上是否有任何参考源;s哈希代码实现,它使用XOR运算符_Java_Android - Fatal编程技术网

Java Android Pair'上是否有任何参考源;s哈希代码实现,它使用XOR运算符

Java Android Pair'上是否有任何参考源;s哈希代码实现,它使用XOR运算符,java,android,Java,Android,当我看到Android Pair的“旧”版本的hashCode时,它的实现如下所示: Josh Bloch的有效Java- 然而,当我看到“最新”版本的Android Pair的hashCode,它看起来是这样的 我可以知道,关于为什么要使用XOR运算符,有没有参考资料?我认为我们不应该违反Josh Bloch的教导:)?不清楚作者为什么要从素数技术转向XOR技术,但这种改变的动机是需要在对类中支持null值。请参阅此提交:。理论上,如果两个对象都不是null,那么实现可以使用旧版本,但如果其中

当我看到Android Pair的“旧”版本的hashCode时,它的实现如下所示:

Josh Bloch的有效Java-

然而,当我看到“最新”版本的Android Pair的
hashCode
,它看起来是这样的


我可以知道,关于为什么要使用
XOR
运算符,有没有参考资料?我认为我们不应该违反Josh Bloch的教导:)?

不清楚作者为什么要从素数技术转向XOR技术,但这种改变的动机是需要在
类中支持
null
值。请参阅此提交:。理论上,如果两个对象都不是
null
,那么实现可以使用旧版本,但如果其中一个是,那么hashCode将成为该对的非null组件的hashCode(或者如果两者都为null,则为
0

/**
 * Compute a hash code using the hash codes of the underlying objects
 * @return a hashcode of the Pair
 */
public int hashCode() {
    int result = 17;
    result = 31 * result + first.hashCode();
    result = 31 * result + second.hashCode();
    return result;
}
/**
 * Compute a hash code using the hash codes of the underlying objects
 *
 * @return a hashcode of the Pair
 */
@Override
public int hashCode() {
    return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
}