今天看了一下commons-logging的源码,看到Log接口的实现类的时候,发现一个问题,在这些实现类的构造方法中,为成员变量name和logger赋值之前,都会先把它们置为null。以Log4JLogger为例吧:
public class Log4JLogger implements Log, Serializable {
private transient Logger logger;
private String name;
public Log4JLogger() {
logger = null;
name = null;
}
public Log4JLogger(String name) {
logger = null;
this.name = null;
this.name = name;
logger = getLogger();
}
public Log4JLogger(Logger logger) {
this.logger = null;
name = null;
name = logger.getName();
this.logger = logger;
}
//.......getter、setter等其他代码.........
}
这样做有什么好处呢? |