當我看到Android的對的hashCode
「舊」版本的任何參考源,它的實施是繼在有沒有在Android對的的hashCode實現,它使用XOR運算
喬希布洛赫的Effective Java的文本 - Best implementation for hashCode method
"Old" Pair.java
/**
* 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;
}
然而,當我看到Android的對的hashCode
「最新」 版本,它看起來像這樣
"New" Pair.java
/**
* 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());
}
我想知道,有沒有什麼參考源,爲什麼正在使用XOR
操作?我認爲我們不應該違反Josh Bloch的教導:)?