I want derived classes to have their own loggers, but it looks like I cannot:
abstract class C {
final protected static Logger l;
C (...) {
l.emit("C");
}
}
class C1 extends C {
final protected static Logger l = new Logger("C1");
C1 (...) {
super(...);
l.emit("C1");
}
}
I want a Logger
in C1
but not in C
, so that new C1()
produces this output:
C1: C
C1: C1
(the first line comes from the C
constructor and the second line from the C1
constructor). Instead I get a nullPointerException
in C
because l
there is null
.
I cannot make l
into abstract
in C
, and I do not want to init it there either because then the output would be
C: C
C1: C1
What are my options?
Thanks!