Today, I found myself coding something like this ...
public class LocalEnums {
public LocalEnums() {
}
public void foo() {
enum LocalEnum {
A,B,C
};
// ....
// class LocalClass { }
}
}
and I was kind of surprised when the compiler reported an error on the local enum
:
The member enum LocalEnum cannot be
local
Why can't enums be declared local like classes?
I found this very useful in certain situations. In the case I was working, the rest of the code didn't need to know anything about the enum
.
Is there any structural/design conflict that explains why this is not possible or could this be a future feature of Java?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…