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.

CLASSES Enums 8.9<br />

DISCUSSION<br />

This implies that it is impossible to define a local (§14.3) enum, or to define an enum in an<br />

inner class (§8.1.3).<br />

Any constructor or member declarations within an enum declaration apply to<br />

the enum type exactly as if they had been present in the class body of a normal<br />

class declaration unless explicitly stated otherwise.<br />

<strong>The</strong> direct superclass of an enum type named E is Enum. In addition to the<br />

members it inherits from Enum, for each declared enum constant with the<br />

name n the enum type has an implicitly declared public static final field<br />

named n of type E. <strong>The</strong>se fields are considered to be declared in the same order as<br />

the corresponding enum constants, before any static fields explicitly declared in<br />

the enum type. Each such field is initialized to the enum constant that corresponds<br />

to it. Each such field is also considered to be annotated by the same annotations as<br />

the corresponding enum constant. <strong>The</strong> enum constant is said to be created when<br />

the corresponding field is initialized.<br />

It is a compile-time error for an enum to declare a finalizer. An instance of an<br />

enum may never be finalized.<br />

In addition, if E is the name of an enum type, then that type has the following<br />

implicitly declared static methods:<br />

/**<br />

* Returns an array containing the constants of this enum<br />

* type, in the order they’re declared. This method may be<br />

* used to iterate over the constants as follows:<br />

*<br />

* for(E c : E.values())<br />

* System.out.println(c);<br />

*<br />

* @return an array containing the constants of this enum<br />

* type, in the order they’re declared<br />

*/<br />

public static E[] values();<br />

DRAFT<br />

/**<br />

* Returns the enum constant of this type with the specified<br />

* name.<br />

* <strong>The</strong> string must match exactly an identifier used to declare<br />

* an enum constant in this type. (Extraneous whitespace<br />

* characters are not permitted.)<br />

*<br />

* @return the enum constant with the specified name<br />

251

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

Saved successfully!

Ooh no, something went wrong!