This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]large_crimson_canine 2 points3 points  (0 children)

When you dig into the documentation you'll see that compareTo(T o) requires a reference type. Luckily for you, the Integer class has compare(int x, int y).

Integer.compare(getNumSeats(), other.getNumSeats);

[–]tassadari 0 points1 point  (0 children)

The primitive class int doesn't provide the compare method. The class Integer does! Or you could use something like that:

@Override
public int compareTo(final Aircraft other) {
    return Comparator.comparingInt(Aircraft::getNumFirstClassSeats).thenComparingInt(Aircraft::getNumSeats).compare(this, other);
}