Because equals() is implemented. Two Points that are equals() will not
have the same hashCode(), which is wrong. It only matters, I suppose,
if Point is used in some context where it matters, like a HashMap key.
But it is used as a HashMap key here! It happens to succeed because
get() is only ever called with the very object instance in the
HashMap. Because it's the same instance it will have the same
hashCode() as itself of course.

This is a 7 on a scale of 10 in terms of bad Java coding. It's also
the kind of thing static analysis tools in your IDE would not let you
write in the first place.

(And on a much smaller point, the iteration should have been over
Map.entrySet() to begin with rather than pointlessly looking up the
key in the loop, twice. Obviously makes very little difference here;
I've had to fix this in many places in Mahout where it makes a
performance difference. Same comment -- 1-click fix in IntelliJ, but
without tool support this won't occur to the average Java developers.)

On Thu, Jun 28, 2012 at 2:43 AM, Ted Dunning <ted.dunn...@gmail.com> wrote:
> Heh?
>
> Why would one be needed in this example?
>
> Sent from my iPhone
>
> On Jun 27, 2012, at 4:41 PM, Lance Norskog <goks...@gmail.com> wrote:
>
>> (Still no hashCode().)

Reply via email to