Ahh...

Thanks for pointing that out.  This isn't intended for inclusion.  It was
intended to help out a user with their own code.  The code had other
problems that I fixed, but I didn't catch the equals issue (I also didn't
run analysis on the code).

On Thu, Jun 28, 2012 at 3:32 AM, Sean Owen <[email protected]> wrote:

> 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 <[email protected]>
> wrote:
> > Heh?
> >
> > Why would one be needed in this example?
> >
> > Sent from my iPhone
> >
> > On Jun 27, 2012, at 4:41 PM, Lance Norskog <[email protected]> wrote:
> >
> >> (Still no hashCode().)
>

Reply via email to