Byte类型的compare方法

String和Integer类型在使用compareTo方法的时候都会返回0、1或者-1,但是通过阅读java源代码发现如果对Byte类型使用compareTo方法,它返回的是a-b的值。
举例来说:
public class Test{
    public static void main(String[] args) throws IOException {
        Byte b = 10;
        Byte c = -1;
        System.out.println(b.compareTo(c));
    }
}
打印结果是-11
源代码:
public int compareTo(Byte anotherByte) {
return this.value - anotherByte.value;
    }
不明白java为什么要这样设计Byte类型

你可能感兴趣的:(java,byte,compareTo)