前置说明:equals和==的区别
Java 语言里的 equals方法其实是交给开发者去覆写的,让开发者自己去定义满足什么条件的两个Object是equal的。
A picture is worth a thousand words
The difference between equals and ==
== | equals |
---|---|
Determine whether two variables or instances point to the same memory space | Determine whether the values of the memory spaces pointed to by two variables or instances are the same |
Compare memory addresses | Compare the contents of the string |
Are the references the same | Are the values the same |