wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Does java supports  conditional compilation ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Does java supports  conditional compilation ?" Watch "Does java supports  conditional compilation ?" New topic
Author

Does java supports conditional compilation ?

Ant Swa
Greenhorn

Joined: May 28, 2002
Posts: 13
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:


Anton
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
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 ?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ant Swa
Greenhorn

Joined: May 28, 2002
Posts: 13
thanks, I got the point.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Does java supports conditional compilation ?
 
Similar Threads
Want to remove debug information
conditional compilation
Removing loggin g code in production environment
who to know the platform
how to use fileset in Javac task