Conditional Compilation
Hi
is there any way to use conditional compilation in such a way that in the true condition i have compilable code
and in the false condition i have a code which is not compilable at this moment so that the compiler just ignores it completely (Like in C/C++) and not give any compile time error
Thanks in advance
Regards
Varun
> You can write "meta java source" with # directives
> and pass it through a pre-processor
> to generate your java source.
Hi
Thanks for the reply
can u elaborate on it a bit more or if u have an example
Thanks in advance
Regards
Varun
Of course conditional compilation was left out of java (like multiple inheritance) to make things easier. Gosling merits a large thanks there.
The cases for a kind of conditional compilation can often be better done with
dependency injection or another form of dynamic programming.
You provide an interface XxxService the application uses.
You implement classes DummyXxxServiceImpl and SmartXxxServiceImpl.
Via a config file (properties of xml) you dynamically by java.lang.reflect create either an object of DummyXxxServiceImpl or the latter.
The springframework is which utilises this technique.
> can u elaborate on it a bit more or if u have an exampleI re-read your original post, your question seems to have been answered already.Can you clarify exactly what you would like someone to elaborate on,and exactly what you would wish an example to show?
http://forum.java.sun.com/thread.jspa?threadID=633884&messageID=3678519
Nobody prevents you from letting a Java source through your favourite preprocessor.
xx.c
public class xx {
private final static String when = __DATE__ ;
public static void main(String args[]) {
System.out.println(when);
}
}
posman@linux:~/ivan> gcc -E -P xx.c >xx.java
posman@linux:~/ivan> javac xx.java
posman@linux:~/ivan> java xx
Jun 7 2005