//compareTo
public int compareTo(Integer anotherInteger) {
return compare(this.value, anotherInteger.value);
}
//compare
public static int compare(int x, int y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
compare是靜態的,可以通過類名直接調用.Integer.compare(a,b)
compareTo是非靜態的,只能通過對象名.compareTo()來調用
compareTo內部其實也是直接調用的compare方法.
對象大於目標參數,返回1
對象小於目標參數,返回-1
對象等於目標參數,返回