I'm wondering if there if a Java equivalent for C's
#if 0 ... Some Code ... #endif
Which can be used around code blocks we don't want to compile. Adding block quotes:
/* ... Some Code ... */
also has the same effect, but the problem is, we have to ensure there are no single line comments
// some comment
in the block.
Compile Time Errors are those errors which prevent the code from running because of an incorrect syntax such as a missing semicolon at the end of a statement or a missing bracket, class not found, etc. These errors are detected by the java compiler and an error message is displayed on the screen while compiling.
Java code needs to be compiled twice in order to be executed: Java programs need to be compiled to bytecode. When the bytecode is run, it needs to be converted to machine code.
static final
fields can be use for conditional compilation.
static final boolean DEBUG = false; if (DEBUG) { some code .... }
some code
will be removed by the compiler.
It is also possible to use the assert
keyword to enable and disable some part of the code. Use java -ea: ..
to control if the code should be enabled or disable. See http://docs.oracle.com/javase/1.5.0/docs/guide/language/assert.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With