我通过在下面将Integer更改为int来修复无限循环:
public class IntTest {
public static void main(String[] args) {
Integer x=-1;
Integer total=1000;
while(x != total){
System.out.println("x =" + x + "total ="+ total);
x++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是什么原因?我认为Integer会比较没问题.
谢谢.
java ×1