file.java: private static final boolean DEBUG = false; // this statement is now ALWAYS false if (DEBUG) {System.out.println(.....); } // A good java compiler does NOT // compile this into bytecode.
#undef DEBUG #ifdef DEBUG #define myPrint(a,b,c) printf(a,b,c) #else #define myPrint() #endif
In both cases the code for the debug case should not be compiled. In the java case the compiler should recognize that the if statement is always false and therefore the code cannot be reached. This is of course an IMPLICIT mechanism relying on a good Java compiler. The C case is clear: it depends on the macro variable DEBUG. A statement like #define a //nothing will effectively just remove "a" from the source code and replace it with empty space.