public class TestProgram {
public static void main(String[] args){
Integer i = new Integer(0);
Integer j = new Integer(0);
while(i<=j && j<=i && i!=j){
System.out.println(i);
}
}
}
There's a code like this. In that code, I thought the println syntax in while wouldn't work I'm in an infinite loop. Why is that true?
java
i<=j is auto unboxing and returns true because it is 0<=0. j<=i returns true for the same reason.
An operation of == or != on an object is an operation that compares whether two objects reference the same object. In i!=j, i and j are true because they created different objects. So the above operation becomes true and it keeps returning true and falls into an infinite loop.
539 Uncaught (inpromise) Error on Electron: An object could not be cloned
548 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
549 PHP ssh2_scp_send fails to send files as intended
725 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.