Click to See Complete Forum and Search --> : Clarification on earlier query


shreyaas
April 19th, 2001, 09:56 AM
First of all i would like to thank Timo Hahn for his immediate response.

My query was
------------

Is there a way to conditionally compile the same source file with more than one version of java.

For example
-----------
In C if #ifdef and #else is specified, it differentiates,selects during COMPILE time the chunk of code and leaves the other chunk UNCOMPILED.

Like wise in java for the below given piece of code,on java1.1.8 version, i want only the "if" part to get COMPILED and leave uncompiled the "else" part.

if (java118)
{
//code for 1.1.8 should only get compiled
}
else
{
//code for 1.2.2 should not get compiled at all.
}

Please note the above query is in regard with COMPILE TIME.

Kindly clarify my doubt.
R.S.Govindarajan

dlorde
April 19th, 2001, 11:25 AM
Timo's method should be effective at compile time, because the 'if' expression is a static final variable, so the compiler has a guarantee it can't change. This means that the block that doesn't satisfy the expression can be safely stripped out at compile time.

Dave

To email me remove '_spamjam' from my email address