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

Complete List of Cybersecurity Acronyms

Cybersecurity news and best practices are full of acronyms and abbreviations. Without understanding what each one means, it's difficult to comprehend the significance of...

Human Resources Management System

A Human Resources Management System (HRMS) is a software application that supports many functions of a company's Human Resources department, including benefits administration, payroll,...

How To Defend Yourself Against Identity Theft

Almost every worldwide government agency responsible for identity theft issues will tell you the same thing: The first step to fighting identity theft is...

Infographic

An infographic is a visual representation of information or data. It combines the words information and graphic and includes a collection of imagery, charts,...

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...