如果我有一个布尔字段,如:
private static final boolean DEBUG = false;
在我的代码中我有如下声明:
if(DEBUG) System.err.println("err1");
Java预处理器是否只是删除了if语句和无法访问的代码?
获取以下Java代码段:
....
else if (true){ //hard-coded as true
///launch methodA
}
else {
///launch methodA (same code as in the ` else if ` statement)
}
....
Run Code Online (Sandbox Code Playgroud)
我想知道的是编译器如何处理这个问题.编译器else if(true)完全删除语句以便不必执行检查是不合逻辑的,即使它被硬编码为真.特别是在Eclipse中,上面的代码是如何解释的?
或者在以下场景中如何:
....
else if (true){ //hard-coded as true
///launch methodA
}
else {
///launch methodBB
}
....
Run Code Online (Sandbox Code Playgroud)
在这种情况下编译器删除else语句不是合乎逻辑的吗?因为在运行时,else语句无法访问.