• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does java supports conditional compilation ?

 
Ant Swa
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
C++ has this powerfull feature of conditional compilation. It enables choosing between different code segments to compile depending on a flag. Does Java has a similar feature. ?
Say, for example, for a paricular program we can compile a debug version with System.out messages. and a production version without the messages if that kind of feature is avalable.
Please enlighten me..
:roll:
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two answers to this, really.
The first second answer is that, no, java does not have a built-in preprocessor like C and C++ do, so it has not got conditional compilation. There's nothing stopping you running any external preprocessor you like over your code before you compile it, though. Checkout freely available preprocessors such as "m4".
The second answer is that, no, Java does not have a preprocessor, but it does have a pretty smart compiler, and if you do something like:

It probably won't bother generating the code for the print. The compiler knows at compile time that the code can never be executed, because the "if" condition is "final".
Has this helped ?
 
Ant Swa
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, I got the point.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic