Jeanne Boyarsky wrote:First of all, I don't check the forums when at work. Let's not bump things unless it has been 24 hours.
What is the method signature of hashCode(). Is it hashCode(Object o)? Your post seems to imply that it is. Check.
Also, I'm trying to wait until January to post the answer to see if others want to try it out.
Stefan wrote:I've gotten rid of the "null" argument with this change.
How does that change the answer now?
piet wrote:What I don't understand is the constant outcome of the last four lines:
keyset contains new Boyarski2(10)? : false
valuesin map<I, B>: [Boyarski2: 1, Boyarski2: 2, Boyarski2: 3, Boyarski2: 4, Boyarski2: 5]
values contain new Boyarski(10)? : false
B(10) equals B(12)? false
No Boyarski equals any other Boyarski, no matter whether equals returns true or false. So either I made one or more programming errors, or there are things that are beyond me (probably both). Hmmm....
Piet Souris wrote:Be that as it may, I checked whether two Boyarski's were equal and I get false, even when the equals method returns true in all cases. So either I made a programming error, or else something else is going on. The map part was intended to find out if the buckets were nicely filled, which they were, so the non overridden hashCode() is being used here. Still puzzled, I hoped to get some clues as to whether this hashCode(Object o) is being used somewhere, no sign of it yet.
Igor Soudakevitch wrote:..."Always override hashCode when you override equals."
Stefan Evans wrote:Jeanne did say that at least one of the answers is valid if you remove the override annotation, but you have eliminated them all - just with the requirements for the equals method contract.