Nested Java enum definition – does declaring as static make a difference? [duplicate]

No, it makes no difference. However the reason is not because it is a member declaration inside an interface, as Jon says. The real reason is according to language spec (8.9) that

Nested enum types are implicitly
static. It is permissable to
explicitly declare a nested enum type
to be static.

At the following example static does not make any difference either (even though we have no interface):

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

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

Another example with a nested private enum (not implicitly public).

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

Leave a Comment