【发布时间】:2018-04-06 10:24:18
【问题描述】:
log4j中有一个类,如下所述
public final class NOPLogger
extends Logger
{
public NOPLogger(NOPLoggerRepository repo, String name)
{
super(name);
this.repository = repo;
this.level = Level.OFF;
this.parent = this;
}
如您所见,NOPLogger 的构造函数中有四个参数。
第一个参数 super(name) 我可以理解派生自 Logger(父类),但是其他三个实例变量呢。据我所知,它们应该在类级别声明,但不存在,如您所见。当我跟踪这些变量时,我在下面的类中找到了它们
public class Category
implements AppenderAttachable
{
protected String name;
protected volatile Level level;
protected volatile Category parent;
private static final String FQCN = Category.class.getName();
protected ResourceBundle resourceBundle;
protected LoggerRepository repository;
AppenderAttachableImpl aai;
protected boolean additive = true;
我可以知道如何在构造函数(NOPLogger)中考虑这三个变量,甚至没有首先在类级别(NOPLogger)声明它们吗?
我只是想知道,只是解释了我已经知道的(我错了吗?)并且想知道理解这个概念在哪里落后?
谁能帮忙?
【问题讨论】:
-
因为这三个变量是受保护的,所以你可以在你的类中修改
-
@0ddlyoko,好的,但你不认为它们之间应该有一些联系(NOPLoggerCategory)如果我从另一个类(Category)中获取它们?或者我可以从其他公开变量的类中获取任何位置?
标签: java