Java Reference
In-Depth Information
8.9.2. Enum Body Declarations
Any constructor or member declarations within an enum declaration apply to the enum type
exactly as if they had been present in the class body of a normal class declaration, unless
explicitly stated otherwise.
It is a compile-time error if a constructor declaration of an enum type is public or protected .
If an enum type has no constructor declarations, then a private constructor that takes no para-
meters (to match the implicit empty argument list) is automatically provided.
It is a compile-time error for an enum declaration to declare a finalizer. An instance of an
enum type may never be finalized.
It is a compile-time error for an enum type E to have an abstract method m as a member
unless E has one or more enum constants, and all of E 's enum constants have class bodies
that provide concrete implementations of m .
In addition to the members that an enum type E inherits from Enum< E > , for each declared
enum constant with the name n , the enum type has an implicitly declared public static final
field named n of type E . These fields are considered to be declared in the same order as the
corresponding enum constants, before any static fields explicitly declared in the enum type.
Each such field is initialized to the enum constant that corresponds to it. Each such field is
also considered to be annotated by the same annotations as the corresponding enum con-
stant. The enum constant is said to be created when the corresponding field is initialized.
In addition, if E is the name of an enum type, then that type has the following implicitly
declared static methods:
Click here to view code image
/**
* Returns an array containing the constants of this enum
* type, in the order they're declared. This method may be
* used to iterate over the constants as follows:
*
* for(E c : E.values())
*
System.out.println(c);
*
* @return an array containing the constants of this enum
* type, in the order they're declared
*/
public static E[] values();
/**
* Returns the enum constant of this type with the specified
Search WWH ::




Custom Search