Setting a variable (NDEBUG) during compilation of a JDK 1.1 applet

O

Oliver Wong

Roedy Green said:
the one thing unusual about java is

static final boolean debug = false;


if ( debug )
{
stuff;
}

generates zero code. It is all eliminated at compile time.

Granted it clutters your source code, but it does not clutter the
executable.

Technically, this is a feature of the compiler, rather than the Java
language itself. There may be compilers out there that will generate
"non-zero" code for the above. I don't know about more recent versions of
Sun's javac, but back in the 1.4 days, there was a lot of dead-code
elimination and constant folding that the compiler wouldn't do.

- Oliver
 
R

Roedy Green

Yeas but for a different purpose, what you are describing is for runtime
recognition of command line properties, what he was thinking of was for
compile time properties.

Yes it would be nice to be able to pass a parameter of the form:
dateCompiled
compilerUsed
debugging

to set a value for a static final at compile time.
 
R

Roedy Green

Technically, this is a feature of the compiler, rather than the Java
language itself.

IIRC somebody told me you can count on it. Presumably it in is the
JLS somewhere.
 
C

Chris Smith

A. Farber said:
Ok, good to know. Too bad java doesn't allow a "javac -J-Ddebug=true"
command line option to set that variable in a C-way.

Ant does text substitution of tokens in source files. If you're willing
to make that leap, it's generally considered a standard solution to that
problem.

The more kludgy answer is to change source paths so as to substitute a
new source file that defines the constant in a different way.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,332
Latest member
LeesaButts

Latest Threads

Top