|
hi,
this is a general Java questions:
i'm just starting to work with Java/Java3D and was
wondering of a way to create a general debug mechanism/module. basically i
come from working with C and using #define's and #ifdef's and i want to have
something like
#ifdef JACK_DEBUG
// do some debug stuff
#endif
in my java classes that i create.
i understand that javac will compile out the code
block if JACK_DEBUG = false:
if ( JACK_DEBUG ) {
// code
}
i'm interested in a way to have JACK_DEBUG be a
global variable despite the fact that Java doesn't support global fields.
i'm thinking that i can create a general interface
(ie JackDebugInterface) which all classes i create can "implement":
public interface JackDebugInterface {
public static final boolean
JACK_DEBUG = true; // or false
// Other debug
functionalities
public void
jackDebugPrint(String);
// .. etc
}
public class JackClass implements
JackDebugInterface {
// ...
if ( JACK_DEBUG ) {
// debug
stuff
jackDebugPrint("Debugging");
}
// ...
}
is this kosher or is there a better way of
designing debug modules? also, if JACK_DEBUG == false, i know javac will
compile out the code block but what about the extra bytecode generated with all
my JackClass's "implements"ing the JackDebugInterface? will that affect
performance from unnecessary bytecode explosion in a non-debug build? is
javac smart enough to know that if the JackDebugInterface is never used due to
JACK_DEBUG being false, it will just not compile the interface in with the other
classes or am i expecting too much from javac? will it compile out the
whole interface if on a release build, i just comment out the code block in my
JackDebugInterface declaration - ie:
public interface JackDebugInterface {
/*
// code block
*/
}
thanks for any advise.
jack
|
