[Tecnología Java Core (Volumen I)] - Juzgar la igualdad

public boolean equals(Object otherObject) {
    
    
	// a quick test to see if the objects are identical
	if (this == otherObject) return true;
	
	// must return false if the explicit parameter is null
	if (otherObject == null) return null;
	
	// if the classes don`t match, they can`t be equal
	var other = (Employee) otherObject;
	
	// test whether the fields have identical values
	return Objects.equals(name, other.name)
		&& salary == other.salary && Object.equals(hireDay, other.hireDay);
}

Supongo que te gusta

Origin blog.csdn.net/piano9425/article/details/111165174
Recomendado
Clasificación