W
Wibble
Piotr said:So what about line like this:
logger.logWarningIf(entry == null
&& logger.setMessage("No entry found in storeEntries for
arcfilename: " + arcfileName));
Thanks to use of Java '&&' operator second operand will be computed only
when the first one is true. As the result no message build is performed
unless really needed.
In this case Logger must buffer your message before commitment of the
printout, like in the following example:
public class Logger {
private String message;
public void logWarningIf(boolean needToLogIt) {
if (needToLogIt) {
System.out.println("warning: "+ message);
}
}
public boolean setMessage(String msg) {
message = msg;
return true;
}
}
P.S.
I've never used it, my preference is classic if (...) { log... }
scenario, and honesty saying I can't see any reason to switch to
something else.
Regards,
piotr
And of course don't make that Logger a singleton since its not
thread safe.