/**
* Returns true if the specified object is equal to this
* enum constant.
*
* @param other the object to be compared for equality with this object.
* @return true if the specified object is equal to this
* enum constant.
*/
public final boolean equals(Object other) {
return this==other;
* Returns true if the specified object is equal to this
* enum constant.
*
* @param other the object to be compared for equality with this object.
* @return true if the specified object is equal to this
* enum constant.
*/
public final boolean equals(Object other) {
return this==other;
}
上面是JDK的源代码,只有2个同为enum的引用并且指向同一个enum元素的时候,equals才返回真,本想String类型和enum比较的的时候,enum对象会不会自动toString(enum的toString函数返回变量名)然后比较呢,答案是没有。