`
570421779
  • 浏览: 44853 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

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类型
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics