0
question about hashCode in java
public int hashCode() { final int prime = 31; int result = 1; result = prime * result + id; return result; } can you explan how this code work ,and what is the benefit? ?
1 Réponse
+ 2
I'm not sure about Java but I think it's a unique value representing a unique object, there's 2 ways to define/override it, multiple it by prime numbers or use the id from the relative database:
// written in C#
public override int GetHashCode()
{
return Person?.Id;
}
The benefit of this is that every object will be 99% or completely unique depends on how you override it, you can then store them in a hashset, this increases the performance to search for the object