...
Code Block | ||
---|---|---|
| ||
public interface Log { public static final Log NULL = new Log() { public void write(String messageToLog) { // do nothing } }; void write(String messageToLog); } class Service { private final Log log; Service(){ this.log = Log.NULL; } // ... } |
Declaring the log
reference final ensures that its value is assigned during initialization.
...