说我有:
public abstract class Animal {
// SLF4J
private Logger logger = LoggerFactory.getLogger(Animal.class);
// ...etc.
public void setLogger(Logger logger) {
this.logger = logger;
}
public Logger getLogger() {
return this.logger;
}
}
和:
public abstract class Dog extends Animal {
// SLF4J
private Logger logger = LoggerFactory.getLogger(Dog.class);
// ...etc.
public void setLogger(Logger logger) {
this.logger = logger;
}
public Logger getLogger() {
return this.logger;
}
}
然后当我执行以下代码时:
Dog d1 = new Dog();
Animal a1 = new Dog();
- 会
d1
得到“狗”记录器还是“动物”记录器? - 会
a1
得到“狗”记录器还是“动物”记录器? - 是否有更好/更清洁/更安全的方法来编写此代码,以便 Dog 和 Animal 始终获得正确的记录器?