//例子1
static int addInt(int x, int y) {
if (x > 0 && y > 0 && x > Integer.MAX_VALUE - y)
return Integer.MAX_VALUE;
if (x < 0 && y < 0 && x < Integer.MIN_VALUE - y)
return Integer.MIN_VALUE;
return x + y;
}
//例子2
static int addInt2(int a, int b) {
int x = a + b;
if ((x ^ a) < 0 && (x ^ b) < 0) {
// overflow, do something
System.out.println("overflow!");
}
return x;
}
在JVM DEBUG参数中,有一个参数叫"suspend",它的取值有两个,“y”或者“n”,如果您刚开始就想调试的话,将参数设置为"suspend=y",这样Eclipse会远程连接Java应用程序。
如果你想先运行项目,然后连接Eclipse,那么可以将参数设置为"suspend=n",这样的话,Java应用程序会正常运行,之后Eclipse会开始远程连接。