这个才是Object 的equals的源代码
/**
* Indicates whether some other object is "equal to" this one.
*
* The equals
method implements an equivalence relation
* on non-null object references:
*
x
, x.equals(x)
should returntrue
.x
and y
, x.equals(y)
true
if and only ify.equals(x)
returns true
.x
, y
, and z
, ifx.equals(y)
returns true
andy.equals(z)
returns true
, thenx.equals(z)
should return true
.x
and y
, multiple invocations oftrue
false
, provided noequals
comparisons on thex
,x.equals(null)
should return false
.
* The equals method for class Object
implements
* the most discriminating possible equivalence relation on objects;
* that is, for any non-null reference values x
and
* y
, this method returns true
if and only
* if x
and y
refer to the same object
* (x == y
has the value true
).
*
* Note that it is generally necessary to override the hashCode
* method whenever this method is overridden, so as to maintain the
* general contract for the hashCode method, which states
* that equal objects must have equal hash codes.
*
* @param obj the reference object with which to compare.
* @return true
if this object is the same as the obj
* argument; false
otherwise.
* @see #hashCode()
* @see java.util.Hashtable
*/
public boolean equals(Object obj) {
return (this == obj);
}
/**
* Compares this string to the specified object. The result is {@code
* true} if and only if the argument is not {@code null} and is a {@code
* String} object that represents the same sequence of characters as this
* object.
*
* @param anObject
* The object to compare this {@code String} against
*
* @return {@code true} if the given object represents a {@code String}
* equivalent to this string, {@code false} otherwise
*
* @see #compareTo(String)
* @see #equalsIgnoreCase(String)
*/
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
String anotherString = (String)anObject;
int n = count;
if (n == anotherString.count) {
char v1[] = value;
char v2[] = anotherString.value;
int i = offset;
int j = anotherString.offset;
while (n-- != 0) {
if (v1[i++] != v2[j++])
return false;
}
return true;
}
}
return false;
}
//如有疑问加入JAVA/JS学习群50812460
找acc
路径:...\jdk1.5.0_12\ 内的src.zip文件里面是java的源代码,你自己找着看吧,所有都在里面!
public boolean equals(Object obj) {
return (this == obj);
}
去中国代码库