On Mar 11 2008, Sven-Ola T?cke wrote:
> P.S. While I'm not a Java expert - for unbloating software, normally an
> #ifdef is a good thing [tm]. Any analog contructs with this funny
> language?
Dynamically loaded classes can be useful when you want to switch between
implementations. If you want to enable/disable code you can use final
variables (equivalent of consts in C) - the compiler (at least the Sun
compiler) will optimise away unreachable parts of the code. The following
code produces different bytecode depending on the flag, with only one of
the strings included in the bytecode. But if you remove the 'final'
modifier, both strings are included.
class IfDefTest
{
final static boolean FLAG = true;
public static void main (String[] args)
{
if (FLAG) System.out.println ("The flag is true");
else System.out.println ("The flag is false");
}
}
Cheers,
Michael