Skip to main content
Enums
- An enum specifies a list of constant values assigned to a type.
- An enum is NOT a
String or an int; an enum constant's type is the enum type. For example,
SUMMER and FALL are of the enum type Season.
- An enum can be declared outside or inside a class, but NOT in a method.
- An enum declared outside a class must NOT be marked static, final, abstract, protected, or private.
- Enums can contain constructors, methods, variables, and constant class bodies.
- enum constants can
send arguments to the enum constructor, using the syntax BIG(8), where
the int literal 8 is passed to the enum constructor.
- enum constructors can have arguments, and can be overloaded.
- enum constructors can NEVER be invoked directly in code. They are always called automatically when an enum is initialized.
- The semicolon at the
end of an enum declaration is optional. These are legal:enum Foo { ONE,
TWO, THREE} enum Foo { ONE, TWO, THREE};
- MyEnum.values() returns an array of MyEnum's values.