Code below
public class Test16Jit { public static void main(String[] s) { int max = Integer.MAX_VALUE; int i = 0; long li = 0; while (i >= 0) { i++; li++; if (i > max) { System.out.println("i is : " + i); System.out.println("max is : " + max); System.out.println("Woo!! something really went wrong"); } } System.out.println("Value of i: " + i); System.out.println("Total # of iterations: " + li); } }
Outputs below in java 1.7x
Value of i: -2147483648 Total
Outputs below in Java 1.6x
i is : 2147483636 max is : 2147483647 Woo!! something really went wrong Value of i: -2147483648 Total
Is there a reason for this behavior?
Also, if I change
int max = Integer.MAX_VALUE; -> final int max = Integer.MAX_VALUE;
It behaves exactly the same in 1.6x and 1.7x
java
Puru--
source share