How can “while (i == i) ;” be a non-infinite loop in a single threaded application?

前端 未结 12 1112
甜味超标
甜味超标 2020-12-04 09:41

I just got a question that I can\'t answer.

Suppose you have this loop definition in Java:

while (i == i) ;

What is the type of

12条回答
  •  既然无缘
    2020-12-04 10:45

    Not infinite loop, one thread :)

    import static B.*;
    public class A {
        public static void main(String[] args) {
            System.out.println("Still Running");
            while (i == i) ;
        }
    }
    
    
    public class B {
    
        public static int i;
        static {
            System.exit(0);
        }
    }
    

提交回复
热议问题