public enum MyEnum1 {
FOO(BAR), BAR(FOO);
private MyEnum1 other;
private MyEnum1(MyEnum1 other) {
this.other = other;
}
public MyEnum1 getOther() {
return other;
}
}
MyEnum1
生成错误Cannot reference a field before it is defined
,这是可以理解的,因为声明顺序在这里很重要。但是为什么下面会编译?
public enum MyEnum2 {
FOO { public MyEnum2 getOther() { return BAR; } },
BAR { public MyEnum2 getOther() { return FOO; } };
public abstract MyEnum2 getOther();
}
FOO
指的是BAR
之前BAR
定义的,我错了吗?