@@ -120,14 +120,28 @@ <h5><a href="ex/Apple-class.html">Apple</a></h5>
120120 < span class ="name "> hashCode</ span > </ section >
121121
122122 < section class ="desc markdown ">
123- < p > Get a hash code for this object.</ p >
124- < p > All objects have hash codes. Hash codes are guaranteed to be the
125- same for objects that are equal when compared using the equality
126- operator < code > ==</ code > . Other than that there are no guarantees about
127- the hash codes. They will not be consistent between runs and
128- there are no distribution guarantees.</ p >
129- < p > If a subclass overrides < code > hashCode</ code > it should override the
130- equality operator as well to maintain consistency.</ p >
123+ < p > The hash code for this object.</ p >
124+ < p > A hash code is a single integer which represents the state of the object
125+ that affects < code > ==</ code > comparisons.</ p >
126+ < p > All objects have hash codes.
127+ The default hash code represents only the identity of the object,
128+ the same way as the default < code > ==</ code > implementation only considers objects
129+ equal if they are identical (see < code > identityHashCode</ code > ).</ p >
130+ < p > If < code > ==</ code > is overridden to use the object state instead,
131+ the hash code must also be changed to represent that state. </ p >
132+ < p > Hash codes must be the same for objects that are equal to each other
133+ according to < code > ==</ code > .
134+ The hash code of an object should only change if the object changes
135+ in a way that affects equality.
136+ There are no further requirements for the hash codes.
137+ They need not be consistent between executions of the same program
138+ and there are no distribution guarantees.</ p >
139+ < p > Objects that are not equal are allowed to have the same hash code,
140+ it is even technically allowed that all instances have the same hash code,
141+ but if clashes happen too often, it may reduce the efficiency of hash-based
142+ data structures like < code > HashSet</ code > or < code > HashMap</ code > .</ p >
143+ < p > If a subclass overrides < code > hashCode</ code > , it should override the
144+ < code > ==</ code > operator as well to maintain consistency.</ p >
131145</ section >
132146</ section >
133147
0 commit comments