Bad Operand error in a Movie Session Program

> is a numerical comparison operator, and according to JLS Sec 15.20.1:

The type of each of the operands of a numerical comparison operator must be a type that is convertible (ยง5.1.8) to a primitive numeric type, or a compile-time error occurs.

Your Time type cannot be converted to a primitive numeric type, because it’s not a primitive nor a primitive wrapper. Hence the error.

If you want to compare them, the Time time must implement Comparable<Time>, then you can write:

if (time1.compareTo(time2) > 0) { // Like "time1 > time2"
}

Leave a Comment