What is a Java enum
Java Enums
A Java enum
is a special Java "class" that represents a group of constants (unchangeable variables, like final
variables).
A Java enum is for instance :
3 constant values e.g. Blue, Pink, Red
or e.g. the 12 months of the year
or the 7 days of the week etc.
Java enums save you typing the values.
One can get the value from the Java enum.
Java enums avoid spelling errors and provide consistancy.
To create:
enum Level {
BAD,
WORSE,
TERRIBLE
}
To use:
Level myLevel = Level.BAD;
Comments
Post a Comment