10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8.9 Enums CLASSES<br />

250<br />

An enum constant may be preceded by annotation (§9.7) modifiers. If an<br />

annotation a on an enum constant corresponds to an annotation type T, and T has<br />

a (meta-)annotation m that corresponds to annotation.Target, then m must have<br />

an element whose value is annotation.ElementType.FIELD, or a compile-time<br />

error occurs.<br />

An enum constant may be followed by arguments, which are passed to the<br />

constructor of the enum type when the constant is created during class initialization<br />

as described later in this section. <strong>The</strong> constructor to be invoked is chosen<br />

using the normal overloading rules (§15.12.2). If the arguments are omitted, an<br />

empty argument list is assumed. If the enum type has no constructor declarations,<br />

a parameterless default constructor is provided (which matches the implicit empty<br />

argument list). This default constructor is private.<br />

<strong>The</strong> optional class body of an enum constant implicitly defines an anonymous<br />

class declaration (§15.9.5) that extends the immediately enclosing enum type. <strong>The</strong><br />

class body is governed by the usual rules of anonymous classes; in particular it<br />

cannot contain any constructors.<br />

DISCUSSION<br />

Instance methods declared in these class bodies are may be invoked outside the enclosing<br />

enum type only if they override accessible methods in the enclosing enum type.<br />

Enum types (§8.9) must not be declared abstract; doing so will result in a<br />

compile-time error. It is a compile-time error for an enum type E to have an<br />

abstract method m as a member unless E has one or more enum constants, and all<br />

of E’s enum constants have class bodies that provide concrete implementations of<br />

m. It is a compile-time error for the class body of an enum constant to declare an<br />

abstract method.<br />

DRAFT<br />

An enum type is implicitly final unless it contains at least one enum constant<br />

that has a class body. In any case, it is a compile-time error to explicitly<br />

declare an enum type to be final.<br />

Nested enum types are implicitly static. It is permissable to explicitly<br />

declare a nested enum type to be static.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!