create a null PrintWriter
Hi, I don't like to write code like this:
if (verbose) out.println();
where, out is a PrintWriter, coz everytime I should write "if (verbose)".
I want to initialize out according to the value of verbose, like:
public void intializeOut() {
if (verbose) {
out = new PrintWriter(System.out, true);
}
else {
// set out to a null PrintWriter (actually it
// should not be null, otherwise there is
// a NullPointerException.
// however you can still call out.println(),
// though nothing will be printed in anywhere
}
My questions are:
1) Is that possible?
2) Is this way efficient compared with always judge the verbose value?
Thanks very much!
JST

