Questions tagged [enums]

A data type consisting of a set of named values called elements, members or enumerators of the type.

This tag is for questions related to enumeration, enumerated-types (or enums) as related to programming.

In computer programming, an enumerated type (also called enumeration or enum) is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value.

From the wikipedia article on enumerated type

Rust and Swift

Unlike the other languages that take inspiration from , the enums in and are sum types (see, for example, sum types in Haskell):

22254 questions
14
votes
5 answers

How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String description; Letter() { description =…
denchr
  • 4,142
  • 13
  • 48
  • 51
14
votes
6 answers

Converting from String to Enum in C

Is there a convienent way to take a string (input by user) and convert it to an Enumeration value? In this case, the string would be the name of the enumeration value, like so: enum Day { Sunday = 0, Monday = 1, ... } So that if the…
Nealon
  • 2,213
  • 6
  • 26
  • 40
14
votes
2 answers

Using enum types as properties in Objective C

I'm a veteran .NET developer making my first foray into Objective C programming. I'm having difficulty with a property of an enum type. Some context... I have an class header and enum like this: typedef enum { Open, Unavailable, …
user196922
14
votes
2 answers

Create instance of unknown Enum with string value using reflection in C#

I have a problem working out how exactly to create an instance of an enum when at runtime i have the System.Type of the enum and have checked that the BaseType is System.Enum, my value is an int value matching an item in the mystery Enum. The code…
Jarmez De La Rocha
  • 618
  • 2
  • 9
  • 19
14
votes
4 answers

Can you have multiple enum values for the same integer?

In .NET can you have multiple enum values for the same integer? eg. public enum PersonGender { Unknown = 0, Male = 1, Female = 2, Intersex = 3, Indeterminate = 3, NonStated = 9, …
CJ7
  • 22,579
  • 65
  • 193
  • 321
14
votes
8 answers

Overriding abstract method or using one single method in enums?

Consider the below enums, which is better? Both of them can be used exactly the same way, but what are their advantages over each other? 1. Overriding abstract method: public enum Direction { UP { @Override public Direction…
Alvin Wong
  • 12,210
  • 5
  • 51
  • 77
14
votes
6 answers

Can you use Enum for Double variables?

I have created a class for handling Unit Conversion in C#. It is not working as it should only returning strings. Here is the class: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace…
John Ernest Guadalupe
  • 6,379
  • 11
  • 38
  • 71
14
votes
2 answers

iterating over Enum constants in JSP

I have an Enum like this package com.example; public enum CoverageEnum { COUNTRY, REGIONAL, COUNTY } I would like to iterate over these constants in JSP without using scriptlet code. I know I can do it with scriptlet code like…
Dónal
  • 185,044
  • 174
  • 569
  • 824
14
votes
3 answers

Scala - Enumeration vs. Case-Classes

I've created akka actor called LogActor. The LogActors's receive method handling messages from other actors and logging them to the specified log level. I can distinguish between the different levels in 2 ways. The first one: import…
user1768906
14
votes
2 answers

how to compare enum values

I have a question about enum C. I defined an enum in the following way: typedef enum { Hello1 = 1, Hello2 = 2, Hello3 = 3 }Hello Hello hello; int value = 3; then how to compare the value with the value in Hello? for…
user707549
14
votes
8 answers

Java enums mutability usecases and possibilities?

I don't know if I'm the only one to know that, but the values of an enum are not implicitly final and can be modified. enum EnumTest { TOTO("TOTO 1"), TATA("TATA 2"), ; private String str; private EnumTest(String str) { …
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
14
votes
4 answers

Using enum parameters in myBatis dynamic SQL

How to do dynamic SQL in myBatis 3.1.1 based on an enum constant parameter?
Tomer
  • 610
  • 1
  • 7
  • 12
14
votes
3 answers

where is Enum.values() defined?

Every Java enumeration has a static values() method can be used like this for (MyEnum enum : MyEnum.values()) { // Do something with enum } However, I cannot figure out where this method is defined. There's no mention of it in the Javadoc and…
Dónal
  • 185,044
  • 174
  • 569
  • 824
14
votes
2 answers

Does an Enum Class containing 2000+1 Enum Constants hit any limit?

The following code fails with a NullPointerException in main (map==null). The issue occurs only if I define 2001 or more Enum constants, 2000 work fine. Why isn't the static code block not executed? Do we hit any silent limit of the compiler (no…
stacker
  • 68,052
  • 28
  • 140
  • 210
14
votes
1 answer

How to get the numeric value from a flags enum?

Possible Duplicate: Enums returning int value How to get the numeric value from the Enum? THIS IS NOT A DUPLICATE OF EITHER OF THESE, THANKS FOR READING THE QUESTION MODS Suppose I have a number of my flags enum items selected: [Flags] public…
DaveDev
  • 41,155
  • 72
  • 223
  • 385
1 2 3
99
100