tag:blogger.com,1999:blog-8405107760807432973.post714834987873739295..comments2024-01-04T09:55:32.459-08:00Comments on Java Concurrency (&c): Java Puzzlers@Google I/OJeremy Mansonhttp://www.blogger.com/profile/04241094734813086257noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-8405107760807432973.post-79446912053949628552011-05-14T23:40:13.923-07:002011-05-14T23:40:13.923-07:00Here, we cheated a bit. The hashcode for the map ...Here, we cheated a bit. The hashcode for the map entry is the XOR of the key's hashcode and the value's hashcode. When the key and the value are the same (as in, MALE == MALE and FEMALE == FEMALE), the hash codes for both are 0. As a result, they end up in the same bucket.<br /><br />That's probably a good basis for another puzzler.Jeremy Mansonhttps://www.blogger.com/profile/04241094734813086257noreply@blogger.comtag:blogger.com,1999:blog-8405107760807432973.post-60343817601342282182011-05-14T23:06:12.400-07:002011-05-14T23:06:12.400-07:00In several languages, if you manage to change the ...In several languages, if you manage to change the value of an object once it's inside a set, you cause the set to do all sorts of wacky things, since its internal invariants get messed up. In a Java HashSet, I would have expected Map.Entry(Male, Male) and Map.Entry(Female, Female) to have different hash values and so wind up in different buckets, even if it was the same object in each of the Jeffrey Yasskinhttps://www.blogger.com/profile/07441481987954238849noreply@blogger.com