Campbell Ritchie wrote:Welcome to the Ranch
You should always use the code button; I shall try adding it to your post later, and if it works it will look much better
Inspect the documentation for Object#toString(), and I hope that will show where the other two invocations of hashCode occur.
srikanth darbha wrote:
Hi Campbell Ritchie,
Thanks but i did not get the point why the "in the hascode" is being called i have gone through the link which you have given. kindly explain me it would be helpful to me.
Thanks in advance.
Campbell Ritchie wrote:Try overriding the toString method, and you will only get two calls. Notice the unoverridden toString method displays the hash code.
Campbell Ritchie wrote:
Henry is right: why does it not print “in equals”? It is possible that method has been optimised away by the return true;?That is part of its bytecode, so no, it has not been optimised away.
Campbell Ritchie wrote:I see what you mean; if the == operator is called before equals() you will never see that output.
No, you don't. You know nothing about internal implementations, which might change anyway. At least that is the assumption which the programmers made. They know they can use the == test because of the general contract of equals(); it was regarded a not a serious problem that it may be used twice.srikanth darbha wrote: . . . i know in the internal implementation . . .
Campbell Ritchie wrote:It is possible that method has been optimised away by the return true;?