mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-03 09:13:36 +00:00
The hashCode() method now generates a magic prime instead of 0 for the hash of null values; this reduces collisions.
This commit is contained in:
1 parent
23dcc9f5a5
commit
251fd03cd7
25 files changed
+49
-44
No files matched your search
@@ -62,7 +62,7 @@ public class DataExample {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final long temp1 = Double.doubleToLongBits(this.getScore());
|
||||
result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode());
|
||||
result = (result*PRIME) + (this.getName() == null ? 43 : this.getName().hashCode());
|
||||
result = (result*PRIME) + this.getAge();
|
||||
result = (result*PRIME) + (int)(temp1 ^ (temp1 >>> 32));
|
||||
result = (result*PRIME) + Arrays.deepHashCode(this.getTags());
|
||||
@@ -111,8 +111,8 @@ public class DataExample {
|
||||
@Override public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = (result*PRIME) + (this.getName() == null ? 0 : this.getName().hashCode());
|
||||
result = (result*PRIME) + (this.getValue() == null ? 0 : this.getValue().hashCode());
|
||||
result = (result*PRIME) + (this.getName() == null ? 43 : this.getName().hashCode());
|
||||
result = (result*PRIME) + (this.getValue() == null ? 43 : this.getValue().hashCode());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user