Integer.MIN_VALUE和Long.MIN_VALUE没有等价的正值,当取这些值的负值时,将获得相同的值。
负数与翻转所有位并添加一个相同。即:
-x = ~x + 1
因此-0x80000000 = 0x7fffffff 1 = 0x8000000
注意:Math.abs(Integer.MIN_VALUE)== Integer.MIN_VALUE,为负数。这在此方法的javadoc中概述。
技术上有很多答案和类型
byte x = 0;
short x = 0;
char x = 0;
int x = 0;
int x = Integer.MIN_VALUE;
float x = 0.0f;
float x = -0.0f;
long x = 0;
long x = Long.MIN_VALUE;
double x = 0.0;
double x = -0.0;
Byte x = 0;
Short x = 0;
Character x = 0;
Integer x = 0;
Integer x = Integer.MIN_VALUE;
Float x = 0.0f;
Float x = -0.0f;
Long x = 0L;
Long x = Long.MIN_VALUE;
Double x = 0.0;
Double x = -0.0;
类似的Java Puzzler是; when是以下表达式true。
x != x + 0
编辑:浮点有0.0和-0.0。这样你可以考虑-0.0不同的值为0.0,虽然是-0.0 == – ( – 0.0)
注意:Double.compare(0.0,-0.0)> 0注意: