&& operador no se puede aplicar a 'int 'booleano'

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.pagesdevuelve 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) == 0si 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;

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=359958&siteId=1
Recomendado
Clasificación