wood burning stoves 2.0*
The moose likes Java in General and the fly likes 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 » Java in General
Bookmark "conditional compilation" Watch "conditional compilation" New topic
Author

conditional compilation

kumud singh
Greenhorn

Joined: Apr 11, 2000
Posts: 5
Is there any provision of conditional compilation in JAVA as in C and C++ language?
Thanks in advance.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
The closest equivalent is to create a public static final boolean variable in the class you're
working with. Then use that variable as the conditoin in an it statement:

The compiler will still look at the code inside the conditional to see if it parses, but if at compile time it is certain that the condition is false (hence the need for the variable to be final) it won't generate any code for the conditional part.
The other rather bizarre solution, if you want conditional compilation just like you get in C/C++, is to run your java code through a C preprocessor before you feed it to the javac compiler. The preprocessor should execute all the #ifdef statements you want, while ignoring your funky Java code. Probably.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: conditional compilation
 
Similar Threads
who to know the platform
assertions
unreachable statement
Different behaviors with if (true)
Help Me!! Conditional compilation in Java