java 中的判断两个对象是否相等的比较严格的操作

简介

RT

code

public class Employee{
	public boolean equals(Object otherObject) {
		// a quick test to see if the objects are identical
		if(this == otherObjec) return true;
		// must return false if the explicit parameter is null
		if (otherObject == null) return false;
		// if the classes don't match, they can't be equal
		if(getClass() != otherObject.getClass())
			return false;
		// now we know otherObject is a non-null Employee
		Employee other = (Employee) otherObject;
		// test whether the fields have identical values
		return name.equals(other.name)
			&& salary == other.salary
			&& hireDay.equals(other.hireDay)
	}
}

猜你喜欢

转载自www.cnblogs.com/eat-too-much/p/13392279.html