Enumerated Type

In programming, an enum, short for enumerated type, is a user-defined data type consisting of a set of named values called enumerators. Instead of using an integer to represent a set of values, a type with a restricted set of values is used instead. Using enums increases the level of abstraction and lets the programmer focus on the value’s meaning instead of its storage and accessibility. This, in turn, reduces bugs.

Think of the four suits in a deck of playing cards clubs, diamonds, hearts, and spades as four enumerators belonging to an enumerated type named suit. If a variable V is declared having suit as its data type, one can assign any one of those four values (clubs, diamonds, hearts, and spades) to it.

Values and variables of an enum are implemented as fixed-length bit strings that are compatible in format and size with some integer type. In type theory, enums are considered as tagged unions of unit types. Programming languages that use enums include Pascal, Java, and C#.

Enum benefits

Enums provide the following benefits:

  • They are a constant rather than a number, increasing readability of the source code.
  • They provide compile-time type safety and prevent comparing constants in different enums. A function argument, return type, class member, or local variable can be declared as an enum type and the compiler will enforce type safety.
  • Enums group things into a set.
  • In Java, enumeration can be used as a singleton. A single element enum type is considered one of the best ways to implement a singleton.






Abby Braden
Abby Braden
Abby Braden is an award-winning writer and editor for websites such as TechnologyAdvice.com, Webopedia.com, and Project-Management.com, where she covers technology trends and enterprise and SMB project management platforms. When she’s not writing about technology, she enjoys giving too many treats to her dog and coaching part-time at her local gym.
Get the Free Newsletter
Subscribe to Daily Tech Insider for top news, trends & analysis
This email address is invalid.
Get the Free Newsletter
Subscribe to Daily Tech Insider for top news, trends & analysis
This email address is invalid.

Related Articles

Virtual Private Network (VPN)

A virtual private network (VPN) encrypts a device's Internet access through a secure server. It is most frequently used for remote employees accessing a...

Gantt Chart

A Gantt chart is a type of bar chart that illustrates a project schedule and shows the dependency between tasks and the current schedule...

Input Sanitization

Input sanitization is a cybersecurity measure of checking, cleaning, and filtering data inputs from users, APIs, and web services of any unwanted characters and...

IT Asset Management Software

IT asset management software (ITAM software) is an application for organizing, recording, and tracking all of an organization s hardware and software assets throughout...

ScalaHosting

ScalaHosting is a leading managed hosting provider that offers secure, scalable, and affordable...

HRIS

Human resources information system (HRIS) solutions help businesses manage multiple facets of their...

Best Managed Service Providers...

In today's business world, managed services are more critical than ever. They can...