Closed vpop closed 8 years ago
Thank you for your consideration, i didnot get the point that the Math.abs(Integer.MIN_VALUE) equals Integer.MIN_VALUE, not a positive number, and thank you!
Int primitive goes from Integer.MIN_VALUE
, or -231 (−2,147,483,648) to Integer.MAX_VALUE
, or 231-1 (2,147,483,647). There is no positive equivalent for the −2,147,483,648, so Math.abs(−2,147,483,648)
returns the same negative value.
It's all now clear after your explanation, thank you
If the
hashCode()
method returnsInteger.MIN_VALUE
, the return of theMath.abs
call will be negative (Integer.MIN_VALUE
). This produces a negative modulo result, hence a negative array index forCOLORS
.More details on this corner case here, slide 4 (called the histogram mystery).