How to print the address of an object if you have redefined toString method

后端 未结 5 2122
梦毁少年i
梦毁少年i 2020-12-05 02:18

I\'m a newbie to Java. Now I\'m studying equals and == and redefinition of equals and toString.

I would like to use both the toString method that I have redefied and

5条回答
  •  难免孤独
    2020-12-05 02:25

    Here is an in-depth answer about overriding equals and hashcode

    What issues should be considered when overriding equals and hashCode in Java?

    The key point being The relation between the two methods is:

    Whenever a.equals(b), then a.hashCode() must be same as b.hashCode().

提交回复
热议问题