总是被问,其实看完下面的话就明白很多:
One of the most common gotchas for beginning Java programmers involves comparing Objects, especially Strings, with the == operator. Every Object in Java has a unique location in the Java Virtual Machine's memory. The == operator returns true if the two handles on the left and right sides refer to the same location in memory. The function Object.equals() is intended to return true if two handles refer to logically equivalent instances. In the most basic case, this function works by comparing the value of each of the data fields of the two instances and returning true only if they're all equivalent. You should override Object.equals() in your own classes to provide more robust logic:
大概的意思就是是否内存指向同一对象,==是物理上是否相等,而 equals则是逻辑上是否相等。