posted 7 years ago
output:
o=my age is 20and sex is male
hi this is how sting method is being overload6
k=f
k=25669322
f=14978587
as we have learn if two objects are equal ,their hashcodes must be equal as well.
what i want to ask is : here two objects are equal i.e. k and f ,so why their corresponding hashcodes are coming different?
output:
o=my age is 20and sex is male
hi this is how sting method is being overload6
k=f
k=25669322
f=14978587
as we have learn if two objects are equal ,their hashcodes must be equal as well.
what i want to ask is : here two objects are equal i.e. k and f ,so why their corresponding hashcodes are coming different?
posted 7 years ago
That's right. The programmer is responsible for making that happen, by writing a hashCode() method which corresponds to the equals(Object) method.
Because the programmer didn't make that happen.
(And let me move this post to a suitable forum.)
arjun srivastava wrote:as we have learn if two objects are equal ,their hashcodes must be equal as well.
That's right. The programmer is responsible for making that happen, by writing a hashCode() method which corresponds to the equals(Object) method.
what i want to ask is : here two objects are equal i.e. k and f ,so why their corresponding hashcodes are coming different?
Because the programmer didn't make that happen.
(And let me move this post to a suitable forum.)
posted 7 years ago
Yes. If you override one of the two methods, you should override the other, too, and make sure they behave the way they're supposed to.
posted 7 years ago
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the
button.

posted 7 years ago
. . . and indent your code correctly and completely, please.David Newton wrote:Please UseCodeTags . . .

It is sorta covered in the JavaRanch Style Guide. |