当我编译这段代码时
public static void main(String [] args) {
int x = 0;
while(false)
{
System.out.println(hello);
}
}
这段代码出现了编译时错误,提示代码无法到达。
但是当我修改了这段代码:
public static void main(String [] args) {
int x = 0;
boolean result = false;
while(result)
{
x=4;
}
}
它正常工作。
有人能告诉我这种行为背后的原因吗?