Я пытаюсь использовать compareTo с целым числом, но это не позволит мне. Помоги пожалуйста! Вот мой код:compareTo with integer
public int compareTo(Book book)
{
if (this.author.compareToIgnoreCase(book.author) < 0) return -1;
if (this.author.compareToIgnoreCase(book.author) > 0) return 1;
if (this.author.equalsIgnoreCase(book.author))
{
if (this.numOfPages.compareTo(book.numOfPages) < 0) return -1;
else if (this.lyrics.compareToIgnoreCase(song.lyrics) > 0) return 1;
else if (this.lyrics == song.lyrics) return 0;
else return 1;
}
return 0;
}
Какие типы данных this.numOfPages и book.numOfPages и т.д.? – BretC
Они оба ints – user3583313
Если они маленькие 'int', вам может понадобиться 'new Integer (this.numOfPages) .compareTo (book.numOfPages)' может быть? – BretC