Skip to content

Instantly share code, notes, and snippets.

@khotyn
Created January 16, 2012 13:42
Show Gist options
  • Save khotyn/1620929 to your computer and use it in GitHub Desktop.
Save khotyn/1620929 to your computer and use it in GitHub Desktop.
Example of conditional compile in Java

Conditional Compile in Java

Considering the piece of the code above:

public class ConditionalCompile {
	private static final boolean DEBUG = false;

	public static void main(String args[]) {
		if(DEBUG){
			System.out.println("Hello, world!");
		}
	}
}

After compiled, and use javap to see the result:

public static void main(java.lang.String[]);
    Code:
    Stack=0, Locals=1, Args_size=1
    0:	return
    LineNumberTable: 
    line 8: 0

The whole if statement is gone after compiled because the value of DEBUG is false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment