Enumeration (programming)
![]() |
Enumeration (also known as enumerant or simply enum) is a special technique used in programming languages. In general it associates each element of an ordered list with a corresponding integer number. This allows one to work with descriptive values instead of using magic numbers.
Java (since J2SE 5.0)
In the Java programming language a program defining an enum line might look like this:
enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }
It is important to note, that a variable defined in a simple way like
Days day;
is now typesafe. This means, you can only assign enum values to such a variable, not integer numbers.
There is also the possibility to assign each enum entry additional values and certain functions for enhancement. This provide additional functionality over the enum construct in C++, where enum variables are only glorified integers. Java has certain tools for operating with enums and they can be seen more like a full-featured class than a description for integers.
External link
- Sun Enum page – more information about mentioned features