Excluding parts of source code during compilation

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Sep 7 02:27:08 PDT 2011


Hi,
you could do something like:

static final boolean PRODUCT = false;

...

if (PRODUCT) {
//some code here
}



By doing so, the compiler will still compile the body of the if 
statement, but it will generate no bytecode in the resulting classfile 
(as the compiler can statically determine that the branch is never taken).

Note: if you change the value of the compile-time constant PRODUCT (i.e. 
from false to true), it is recommended that you recompile the whole 
project, as compile-time constants are inlined in client classes that 
use them.

Maurizio


On 06/09/11 23:50, suraj puvvada wrote:
> Hi,
>
> Is there a way to exclude parts of code during compilation ? For 
> example I would like exclude a bunch of DEBUG/NON_PRODUCT code for 
> production builds.
>
> NOT_PRODUCT_BLOCK
> {
>   //some statements
> }
>
> or
>
> if(DEBUG || NOT_PRODUCT)
> {
>    //bunch of statements
> }
>
> Thanks
> Suraj

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20110907/be0dc3cc/attachment.html 


More information about the compiler-dev mailing list