5.2.1 The equals method
参考链接:
https://web.mit.edu/6.005/www/fa15/classes/15-equality/
我们先来看 == vs. equals()
-
The == operator compares references. More precisely, it tests referential equality. Two references are == if they point to the same storage in memory. Two references are == if their arrows point to the same object bubble.
-
The equals() operation compares object contents – in other words, object equality, in the sense that we've been talking about in this reading. The equals operation has to be defined appropriately for every abstract data type.
The equals() method is defined by Object, and its default implementation looks like this:
public class Object {
...
public boolean equals(Object that) {
return this == that;
}
}
In other words, the default meaning of equals() is the same as referential equality. For immutable data types, this is almost alway