Integer的int compare(int x, int y)方法为什么不直接用x-y?

今天在查看Integer源码时发现有下面这个方法,为什么要废这么大劲写这么长

public static int compare(int x, int y) {
        return (x < y) ? -1 : ((x == y) ? 0 : 1);
}

比较两个数下意识会做减法,其实这样是不对的,因为每种数据类型都有范围,向上溢出(超过最大值)会从最小值开始计数;向下溢出(小于最小值)会从最大值往回计数。得不到我们需要的结果。

Integer.MAX_VALUE-(-1)结果为-2147483648。

Integer.MIN_VALUE-1结果为2147483647