基本没什么区别, 唯一的区别是前者在继承类中子类可以直接使用,无需重新定义.
public class Father {
protected final Log log = LogFactory.getLog(this.getClass());
void test() {
log.info("father");
}
}
public class Son extends Father{
void test(){
log.info("son");
}
}
因为java类的动态特性, 子类获得log对象其实是LogFactory.getLog(Son.class), 虽然是从父类继承过来
网友评论