Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

conditional complilation  RSS feed

 
jake noi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
How can I achieve conditional complilation? Since java doesn't support pre-processor.
We can't say something like this
#if defined(dohere)
......
#endif
Can we tell complier not to compile some part of the code?
Thank you
Jake
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always run your code through any other preprocessor before passing it to the compiler. This is especially easy if you use a build tool such as ant, but can also be done manually or via batch files or shell scripts.
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jake,
The way to do this is to use a "private final static boolean" flag.
For example,

If you set the isTraceOn flag to false, the compiler will automatically delete this part of the code from the generated byte code in your Foo.class file.
-Peter
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the Prep program at http://www.unclechicken.com/labnotes/flabnote.html
--Mark
hershey@vaultus.com
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!