Why does this not compile, and (relatedly) why is it that CC cannot access what I would have thought (maybe I'm wrong) its own (private) member variable i, when AA and BB can indeed do so? How can CC access its own member variable?
Thank you.
enum TestEnum {
AA(1000), BB(500), CC(100) {
public int getI() {
return i + 1;
}
};
TestEnum(int i) {
this.i = i;
}
private int i;
public int getI() {
return this.i;
}
}
javac output:
TestEnum.java:6: error: non-static variable i cannot be referenced from a static context
public int getI() { return i + 1; }
^
1 error