Should nested enums be declared as static?

2011 views java

I know that there is no difference in functionality if a nested enum is declared as static or not. However, it makes a difference if a nested class is declared as static or not. In comparison to the scheme of nested classes, nested enums would be always static.

The question is: Is there a kind of java code convention which says that the static keyword should be used when declaring nested enums? How is it handled mainly?

The main reason why I ask this question is that I didn't find any discussion about this topic so far and it might help someone who is also searching for this.

answered question

1 Answer


It's pretty much just shooters' preference, but I wouldn't. It's redundant since it's an enum, and might make people think it's okay to use the static enum by itself.

So I guess the question is how tightly coupled is the intent of the two enums? Are you using them just as a set of static constants like C# enums or utilizing full functionality? If they have functionality, and it the functionality of the enclosing enum relies upon the nested enum...definitely don't static it.

posted this

Have an answer?


Please login first before posting an answer.