Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Regards,
Avishkar Nikale
You should also override hashCode.Avishkar Nikale wrote:Dileep,
You will have to override the method & check the contents yourself.
The language will not do it for you.
You are more likely to get help on code with the code tags on, so we can actually read it.dileep keely wrote: . . . Anyone can help me out in this? . . .
Of course he didn't. That was th error I noticed earlier.Matthew Brown wrote: . . . you consider any two ShowHash objects to be equal, regardless of what data they contain. Is that what you intended?
Please don't try altering old posts.dileep keely wrote:
output:
true 10 17523401
false 10 8567361
Jelle klap:
Thanks for your comment!!
I have done according to the suggestion(overriding equals() and hashcode()).I have a query here.
you have commented that
"When we invoke equals() on an instance of Test the implementation will check if the reference you invoke the method on and the reference you supplied to the equals() method refer to the same object".
It implies that it should also satisfy == comparison.If so in the above output I got (false for == and true for equals() comparison
which shouldn't be the case then? because == checks if two references are to the same object)
Anyone can help me out in this?Apologies if my understanding is wrong.
Since I have removed your emendation, please post the correct version again.dileep keely wrote:equals() method is now correctly implemented. . . .
OCPJP 6
OCPJP 6
Actually you want to change the keyword if to the keywordreturn and you have the entire method in one line.Vinoth Kumar Kannan wrote:Yeah....may be you want to do this..
Don't get me started about those stupid light bulbs. |