If you use
private static final boolean DEBUG_ENABLED = @DEBUG@;
and replace @DEBUG@ with either true or false, you can have the C equivalent
of #ifdef DEBUG in your Java code.
As long as the variable is declared as static final, most Java compilers
(including javac) will optimize out code that is written as:
if (Debugging.DEBUG_ENABLED) {
// Do your debugging stuff here
}
The runtime penalty for a debug build is just the debugging code, as the if
statement check is removed when DEBUG_ENABLED is true. I use this technique
for littering assertions throughout my code.
-- Scotte
-----Original Message-----
From: Nico Seessle [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 11, 2000 3:50 AM
To: [EMAIL PROTECTED]
Subject: Re: [PATCH] New <case> task
----- Original Message -----
From: "Diane Holt" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 11, 2000 5:19 AM
Subject: RE: [PATCH] New <case> task
> Don't know what Jose Alberto's particular need is, but I can tell you one
> of the things I'd like it for... I have a property that contains a value
> of either "true" or "false" -- note: it's not something I can have simply
> either set or not-set, because the literal value of it is used as the
> replacement string for a filter token. The token is the value of a boolean
> in a .java file, and depending on whether it is set to "true" or "false"
> determines whether the source-tree is being compiled with debug code or
> without
You CAN do it without scripting or case-tasks with just setting the property
to true or not setting it if you use something like this in your Java-Code
private static final String DEBUG_STRING = "@DEBUG@";
public static final boolean DEBUG =
DEBUG_STRING.toLowerCase().equals("true");
I don't know if and how javac/jikes/your_compiler optimizes this and/or if
it is slower than your solution (at run-time) but it works now :-) And you
can use the already-available target if/unless-solution.
Nico