Hi,

> On 8 Dec 2017, at 11:12, Thomas Mortagne <[email protected]> wrote:
> 
> Hi devs,
> 
> Most Object#hashCode() are implemented using HashCodeBuilder.
> HashCodeBuilder provide an empty constructor and also allow setting
> "random" numbers.
> 
> http://dev.xwiki.org/xwiki/bin/view/Community/JavaCodeStyle#HEquals2FHashCodeandToStringimplementations
> does not really say anything about what do do and when currently so I
> would like to have a clear rule about it.
> 
> On my side when I don't plan to use different types of objects in a
> hash key I usually simply use the empty HashCodeBuilder constructor.
> The only point of setting different numbers is when you might end up
> comparing different object types (and even in that case you have the
> #equals() safeguard anyway so it's mostly about performances in
> practice).
> 
> So here is a proposal: it's OK to use empty HashCodeBuilder constructor 
> except:
> * when overwriting the hachCode of a super class you should use
> different numbers than the super class (since there is big chance to
> have that super class used as a hash key)
> * as a best effect in general if you know that you are going to have
> several different types as hash key, try to make sure they use
> different random numbers, your proc will thank you :)
> 
> WDYT ?

I don’t fully master the topic but I’m trusting you so +0 from me. Only comment 
is that it means there’s not a single way of writing our code and thus is not 
that easy to check.

Thanks
-Vincent


> 
> -- 
> Thomas Mortagne

Reply via email to