Using this works OK for me (based on what GWT's AbstractList's hashCode implementation does):
On Friday, 9 January 2015 10:31:34 UTC, manstis wrote:
-- result = 1;
result = 31 * result + (child1.hashCode());
result = ~~result;
result = 31 * result + (child2.hashCode());
result = ~~result;
Hi,I've done a fair amount of searching but not found anything related (so hopefully this is something stupid I'm doing).I have a class for which I override hashCode() and equals(). The hashCode() method in Java always returns a value Integer.MIN_VALUE<=x<=Integer.MAX_VALUE. Great :) In SuperDevMode and "production" mode (i.e. fully compiled and running in a J2EE container) the hashCode() method returns values less than MIN_VALUE and greater than MAX_VALUE.The problem I encounter comes with the comparison of the hashCodes; e.g. hc1==hc2; where the HashCodes have been calculated similar to the following (I've stepped through my actual code in SDM):HC1result = 1;result = 31 * result + (child1.hashCode()); // child1 hashCode is the same as child1 hashCode belowresult = 31 * result + (child2.hashCode()); // child2's hashCode == 0result = 2.3950366067525864e+39HC2result = 1;result = 31 * result + (child1.hashCode()); // child1 hashCode is the same as child1 hashCode aboveresult = 31 * result + (child2.hashCode()); // child2's hashCode = 100result = 2.3950366067525864e+39GWT evaluates the two hashCodes as equal; whereas in reality they are minimally different (but identical at the precision shown).Can anybody recommend the best practice to generate GWT (JavaScript)-friendly hash codes; or a workaround? (e.g. I notice GWT's AbstractList's hashCode performs "k = ~~ k" to presumably keep the value within limits?).With kind regards,Mike
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment