I've found that java.lang.Integer
implementation of compareTo
method looks as follows:
public int compareTo(Integer anotherInteger) {
int thisVal = this.value;
int anotherVal = anotherInteger.value;
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
}
The question is why use comparison instead of subtraction:
return thisVal - anotherVal;