As a programmer, the only thing you should need to know about this process is the naming conventions that
are used. Consider a static, or non-local, nested type defined as Outer.Inner. This is the source name for
the class. At the virtual machine level the class is renamed as Outer$Innerin essence, dots in a nested
name are converted to dollar signs. For local inner classes, the transformation is less specific because these
classes are inaccessible, hence their name is less importantsuch classes are named Outer$NInner, where
Inner is the name of the local class and N is a sequence of one or more digits. For anonymous inner classes
the names have the form Outer$N, where N is a sequence of one or more digits.
These issues have to be dealt with in two main cases. First, when bundling the class files for your applications
you have to recognize all the strange files with $ in their name. Second, if you use the reflection mechanism
discussed in Chapter 16 to create nested class instances, you'll need to know the transformed name. But in
most programming the transformed name is something you can blissfully ignore.
"A power so great, it can only be used for Good or Evil!"
Firesign Theatre, "The Giant Rat of Summatra"
Chapter 6. Enumeration Types
Four be the things I am wiser to know: Idleness, sorrow, a friend, and a foe. Four be the
things I'd been better without: Love, curiosity, freckles, and doubt. Three be the things I shall
never attain: Envy, content, and sufficient champagne. Three be the things I shall have till I
die: Laughter and hope and a sock in the eye.
Dorothy Parker, "Inventory"
An enumeration typesometimes known as an enumerated type, or more simply as an enumis a type for which
all values for the type are known when the type is defined. For example, an enum representing the suits in a
deck of cards would have the possible values hearts, diamonds, clubs, and spades; and an enum for the days of
the week would have the values Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday.
In some programming languages, enums are nothing more than a set of named integer values, but in the Java
programming language an enum is a special kind of class, with an instance that represents each value of the
enum.
6.1. A Simple Enum Example
An enum for the suits in a deck of cards can be declared as follows:
enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }
In this basic form, an enum declaration consists of the keyword enum, an identifier that names the enum, and
a body that simply names each of the values, or constants, of the enum.[1] By convention, enum constants
always have uppercase names. The enum constants are static fields of the class:
[1] The term enum constant refers to those values, like CLUBS and DIAMONDS, declared in
the enum type. Enum types can also have normal constants, just like other classes, that are
static final fields of various types. We always use "enum constant" to refer to the former, and