The so-called conditional compilation, which is based on conditions set, enables the assembler to assemble a particular section of a program, or not to assemble a particular paragraph. In Java, for example, you might want to output some debug statements during the development phase, and the statements of these tests should not be output when the project is formally running (you might say you can use log4j, of course).
For example, the following section of code:
public class HelloWorld {public static void main (string[] args) {Final Boolean debug = True;if (Debug) {System.out.println (" This is the debug output Information ");}}}
The above code will always output debugging information, which probably gives us some idea to open the compiled class file with the Java Anti-compilation tool, such as:
We found that the above code at compile time, the compiler did some optimizations, the compiler will always be true if the statement processing, directly remove the IF statement, if False then the entire if statement will be directly ignored. In the actual project we may do this:
public class Constant {public static final Boolean debug = True;}
public class HelloWorld {public static void main (string[] args) {if (constant.debug) {System.out.println ("This is debug output information");}}
In the project development phase, set the constant Denug to true to set this constant to False when the project is formally run, which will not only improve efficiency when the project is formally running, but also facilitate debugging at development time.
How Java implements conditional assembler functionality similar to the C language