在下面的代码示例中,我正在尝试测试父类中枚举的值。我得到的错误是“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) { }
}
}
}