Assuming that all my classes in the hierarchy have only the default constructor,what are the issues of creating Log instance as follows ?
public abstract class AbstractService {
protected static Log log=null;
public AbstractService(){
log=LogFactory.getLog(this.getClass().getName());
}
public void foo(){
log.debug("base foo() : ");
}
}
class ServiceA extends AbstractService {
public void foo(){
super.foo();
log.debug("Overloaded foo() in ServiceA");
}
}
class ServiceB extends AbstractService {
public void foo(){
super.foo();
log.debug("Overloaded foo() in ServiceB");
}
}
Given that the “log” field is static (i.e. associated with the AbstractService class), it shouldn’t be set from the constructor (which is associated with a specific instance of that class).
You either need to: