Scott Adamson:
Estoy tratando de reemplazar el método es igual pero estoy frente a un 'operador && no se puede aplicar a 'booleano',' 'error int', que parece ser causado por la última línea. Mi creencia es que pages == otherEntry.pages
devuelve un int, pero ¿por qué?
@Override
public boolean equals (Object that) {
if (this == that) return true;
if (!(that instanceof BookEntry)) return false;
BookEntry otherEntry = (BookEntry) that;
return title.equals(otherEntry.title) &&
Arrays.equals(authors, otherEntry.authors) &&
Float.compare(otherEntry.rating, rating) &&
ISBN.equals(otherEntry.ISBN) &&
pages == otherEntry.pages;
}
Eran :
Float.compare(otherEntry.rating, rating)
devuelve una int
.
Cambiarlo a Float.compare(otherEntry.rating, rating) == 0
si desea determinar si los dos flotadores son iguales de acuerdo con el orden definido por Float.compare()
.
La sentencia return se convertiría
return title.equals(otherEntry.title) &&
Arrays.equals(authors, otherEntry.authors) &&
Float.compare(otherEntry.rating, rating) == 0 &&
ISBN.equals(otherEntry.ISBN) &&
pages == otherEntry.pages;