Double.double的含义ToLongBits(x)
我正在写一个类,表示一个二维向量。我存储和在s。Vec2D
x
y
double
当被要求生成 和 时,eclipse 生成如下:equals(Object obj
hashCode()
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Vec2D other = (Vec2D) obj;
if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
return false;
if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
return false;
return true;
}
在这方面,其意义何在?我不能简单地写吗?Double.doubleToLongBits(x)
x != other.x