【发布时间】:2010-08-06 09:11:26
【问题描述】:
在下面的代码示例中,我正在尝试测试父类中枚举的值。我得到的错误是“p.theEnum 无法解析或不是字段。”,但它与我在父类中用于测试值的代码完全相同(显然没有 p)。
我哪里错了? :)
public class theParent {
protected static enum theEnum { VAL1, VAL2, VAL3 };
private theEnum enumValue = theEnum.VAL1;
theParent() { this.theChild = new theChild(this); this.theChild.start(); }
class theChild {
private parentReference p;
public theChild (theParent parent) { this.p = parent; }
public void run() {
// How do I access theEnum here?
if (p.enumValue == p.theEnum.VAL1) { }
}
}
}
【问题讨论】:
标签: java enums parent protected