- Feb 16, 2003
- 26,108
- 5
- 81
public abstract int compareTo(Object obj);
would that return a boolean saying if they're the same or not?
would that return a boolean saying if they're the same or not?
Originally posted by: pkananen
no, it will return an int (0 and 1 = false and true in C++ is not the same in Java, where boolean is a seperate primitive type not interchangeable with ints 0 and 1).
BUT, its an abstract function - it can't actually be used. You can create a child class where compareTo will be implemented.
Originally posted by: kamper
Technically it doesn't have to be 1 or -1, just >0 or <0
Integer.compareTo(Integer) happens to always return -1 or 1, though. I don't understand why they didn't just return (thisVal - anotherVal).