for loop terminating early when comparing to Integer.MAX_VALUE and using System.out.println

前端 未结 2 1055
梦如初夏
梦如初夏 2021-01-12 03:34

When I run this class the for loop seems to terminate early

class Test {

    public static void main(String[] args) {
        int result = 0;
        int en         


        
相关标签:
2条回答
  • 2021-01-12 03:48

    Its a known bug in Java 6. The JIT optimizes the loop incorrectly. I believe more recent versions of Java don't have this bug.

    http://vanillajava.blogspot.co.uk/2011/05/when-jit-gets-it-wrong.html

    Java 6 update 16 is just over two years old. I suggest you update to the latest version Java 6 update 25 if you can't update to Java 7.

    BTW Java 6 will be End Of Free Support in a couple of months (Dec 2012)

    0 讨论(0)
  • 2021-01-12 04:00

    You can work around the JVM bug by using Integer.MAX_VALUE-1.

    0 讨论(0)
提交回复
热议问题