what is the difference between == operator and equals()? (with hashcode() ???)

后端 未结 6 604
长发绾君心
长发绾君心 2020-11-28 15:20

I was learning hashcode in more depth and figured that:

1. If you override equals(), you must override hashcode() too.

2. To find if

6条回答
  •  有刺的猬
    2020-11-28 16:01

    == is identity.

    .equals() is equality.

    .equals() defaults to just using == (just like hashCode() defaults to System.identityHashCode() but you can override them if there's a more meaningful way to check for equality. Typically this is a sort of "structural" equality. ie: are all of the pieces of this .equal() to all of the pieces of that?

提交回复
热议问题