Java预处理器 [英] Java Preprocessor
本文介绍了Java预处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个布尔字段,如:
If I have a boolean field like:
private static final boolean DEBUG = false;
在我的代码中我有以下语句:
and within my code I have statements like:
if(DEBUG)System.err。 println(err1);
Java预处理器是否只是删除了if语句和无法访问的代码?
does the Java preprocessor just get rid of the if statement and the unreachable code?
推荐答案
大多数编译器都会删除该语句。例如:
Most compilers will eliminate the statement. For example:
public class Test {
private static final boolean DEBUG = false;
public static void main(String... args) {
if (DEBUG) {
System.out.println("Here I am");
}
}
}
编译后这个类,我然后通过 javap
命令打印生成的指令列表:
After compiling this class, I then print a listing of the produced instructions via the javap
command:
javap -c Test
Compiled from "Test.java"
public class Test extends java.lang.Object{
public Test();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."":()V
4: return
public static void main(java.lang.String[]);
Code:
0: return
}
如你所见,没有的System.out.println
! :)
As you can see, no System.out.println
! :)
这篇关于Java预处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文