Bom dia,
Estou com dúvida quanto a questão abaixo.
Não entendi porque a letra D está correta também.
A letra C ok, agora a letra D?
Aguém poderia dar uma mão?
public class SortOf {
String name;
int bal;
String code;
short rate;
public int hashCode(){
return (code.length() * bal);
}
public boolean equals(Object o){
//code here
}
}
/*
Which of the following will fulfill the equals() and hashCode() contracts for this class?
A - return ((SortOf)o).bal == this.bal;
B - return ((SortOf)o).code.length() == this.code.length();
C - return ((SortOf)o).code.length() * ((SortOf)o).bal == this.code.length() * this.bal;
D - return ((SortOf)o).code.length() * ((SortOf)o).bal * ((SortOf)o).rate == this.code.length() * this.bal * this.rate;
===========
Explanation
===========
C and D are correct.
The equals() algorithm must be at least as precise in defining what "meaningfully equivallent"
means as the hashCode() method is.
*/