Мне сказали, что compareTo должен вернуть int ... not Boolean.
Например:
compareTo: как вернуть логическое значение?
Возвращает
0, если равно б
-1, если < б
+1, если а> Ь
Я немного смущен этим. Любая помощь будет принята с благодарностью.
public int compareTo(Cheese anotherCheese)
throws ClassCastException
{
if (!(anotherCheese instanceof Cheese))
throw new ClassCastException("A Cheese object expected.");
if(getCheeseType().compareTo(anotherCheese.getCheeseType()))
return -1;
else if (getCheeseType().compareTo(anotherCheese.getCheeseType()))
return 1;
else
return cheesePrice > anotherCheese.getCheesePrice();
}
Когда я компилирую, я получаю сообщение об ошибке сказав:
несовместимые типы
if(getCheeseType().compareTo(anotherCheese.getCheeseType()))
несовместимые типы
else if (getCheeseType().compareTo(anotherCheese.getCheeseType()))
несовместимые типы
return cheesePrice > anotherCheese.getCheesePrice();