嵌套的Java枚举定义 – 确实声明为静态有所作为?

我有一个接口 – 这是一个很好的作为例子:

public interface Particle { enum Charge { POSITIVE, NEGATIVE } Charge getCharge(); double getMass(); etc... } 

如果我将Charge枚举定义为静态,这种方式的执行方式会有什么区别吗?

 public interface Particle { static enum Charge { POSITIVE, NEGATIVE } Charge getCharge(); double getMass(); etc... } 

不,这没有什么区别。 然而,原因并不是因为它是一个接口内的成员声明,​​正如乔恩所说。 真正的原因是根据语言规范( 8.9

嵌套的枚举types是隐式静态的。 显式声明一个嵌套的枚举types是静态的是允许的。

在下面的例子中,static也没有任何区别(即使我们没有接口):

 public class A { enum E {A,B}; } public class A { static enum E {A,B}; } 

嵌套私有枚举的另一个例子(不隐式公开)。

 public class A { private static enum E {A,B} } 

不,这没有什么区别。 从语言规范,第9.5节 :

接口可能包含成员types声明( §8.5 )。 接口中的成员types声明是隐式static也是public