我正在研究OpenJDK的源代码。
Byte.compare()
和Integer.compare()
这两个方法引起了我的注意:
public static int Byte.compare(byte x, byte y) {
return x-y;
}
public static int Integer.compare(int x, int y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
为什么Byte.compare()
和Integer.compare()
方法有不同的实现方式?
return (x < y) ? -1 : ((x == y) ? 0 : 1);
。 - senseiwu