Enums

An enum declaration has the form:

EnumDeclaration: ClassModifiersopt enum Identifier Interfacesopt EnumBody

EnumBody: { EnumConstantsopt ,opt EnumBodyDeclarationsopt } The body of an enum type may contain enum constants. An enum constant defines an instance of the enum type. An enum type has no instances other than those defined by its enum constants. EnumBodyDeclarations: ; ClassBodyDeclarationsopt An enum constant may be preceded by annotation modifiers. If an annotation a on an enum constant corresponds to an annotation type T, and T has a (meta-)annotation m that corresponds to annotation.Target, then m must have an element whose value is annotation.ElementType.FIELD, or a compile-time error occurs. An enum constant may be followed by arguments, which are passed to the constructor of the enum type when the constant is created during class initialization as described later in this section. The constructor to be invoked is chosen using the normal overloading rules. If the arguments are omitted, an empty argument list is assumed. If the enum type has no constructor declarations, a parameterless default constructor is provided (which matches the implicit empty argument list). This default constructor is private. The optional class body of an enum constant implicitly defines an anonymous class declaration that extends the immediately enclosing enum type. The class body is governed by the usual rules of anonymous classes; in particular it cannot contain any constructors.