Skip to main content

Questions tagged [enum]

Enum (also enumeration) 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, and are often predefined with an implied ordering.

Filter by
Sorted by
Tagged with
10 votes
3 answers
22k views

I'm running into issues with an approach I am taking and am now wondering if I just started down the wrong path and should rethink my approach. Here is what I attempting. I would like to use an Enum ...
forevernewb123's user avatar
2 votes
1 answer
5k views

I'm working on a Java library for sorts for Magic: the Gathering. Well, without going into a lot of detail, in the game there are five different colors of magic: white, blue, black, red, and green. ...
codebreaker's user avatar
  • 1,764
10 votes
9 answers
12k views

In most popular programming languages like Java and C# there is a way to define enums, which are essentially datatypes with a fixed set of values, e.g. DayOfWeek. The problem is, given a value, e.g. ...
proskor's user avatar
  • 595
2 votes
3 answers
8k views

I am working on a project where there will be plenty of static options being stored in the database. I looked at using Enums for this, but do not see how they could be useful. They do not create any ...
Lotok's user avatar
  • 1,819
2 votes
2 answers
1k views

Suppose in a manufacturing environment, there are certain stock materials available for use in a product. For example, there are only a few different sizes of copper tube, each having a specific ...
Ethan's user avatar
  • 167
6 votes
5 answers
17k views

I often use enum types in my code with a switch to apply logic to each type. In these cases it's important that each enum has code implemented. For example; public enum eERROR { REQUIRED, ...
Reactgular's user avatar
  • 13.1k
4 votes
1 answer
3k views

What are a few ways constants and enums are dealt with when creating an API Client? I'm writing a client in python for our API and I've hit a sticking point with this. We use a lot of mappings to ...
tonyl7126's user avatar
  • 297
3 votes
2 answers
1k views

Are the IETF BCP 47 language tags defined as enums anywhere in JDK? For Locale.forLanguageTag() we pass values like fr-FR, jp-JP etc. Are there any enums already provided by JDK for it? Or should ...
jaadhimalli's user avatar
4 votes
1 answer
5k views

I have my enum like this. enum Size{PAGE_SIZE=20, HEADER_SIZE=30 }; I only use them as constants(No enum variable created) in my program. i.e= int x = PAGE_SIZE + 20; So what is the better ...
sk patra's user avatar
  • 457
37 votes
3 answers
42k views

I am working on a simple API that I want to use for my own client, and to open to the public in the future. I have "Item" objects which can have different "types". The type is a C &...
Julien's user avatar
  • 473
9 votes
3 answers
10k views

I was recently told that using Enum: public enum TaskEndState { Error, Completed, Running } may have compatibility/serialization issues, and thus sometimes it's better to use const string: public ...
Yosi Dahari's user avatar
3 votes
1 answer
2k views

I have AS3/PHP background and some basic understaning of enums from C++. Saying shortly: I read this: http://haxe.org/ref/enums http://haxe.org/doc/cross/more_on_enum And though - good heavens! ...
Łukasz Zaroda's user avatar
7 votes
7 answers
9k views

Enumerations1 are often associated with procedural code rather than object-oriented code. They tend to give rise to similar switch statements scattered through the code, and in general, these are ...
Kazark's user avatar
  • 1,820
1 vote
3 answers
1k views

Does an in-code enumeration provide a stronger domain model than a static database table? As an example, say I have an Marble entity, with a Color attribute. The color attribute has a finite set of ...
Kazark's user avatar
  • 1,820
0 votes
2 answers
1k views

I just have read some stuff on enum today. Use of flags with enum was something interesting and new for me. But often practice and theoretical uses are different. I go through many articles they ...
user576510's user avatar
9 votes
2 answers
573 views

I was reading this article: Designing Flags Enumerations @ msdn and it says Combining flags enumeration values is an intermediate skill that should not be required for developers implementing common ...
Rowan Freeman's user avatar
77 votes
8 answers
110k views

An enum X : int (C#) or enum class X : int (C++11) is a type that has a hidden inner field of int that can hold any value. In addition, a number of predefined constants of X are defined on the enum. ...
Daniel A.A. Pelsmaeker's user avatar
9 votes
4 answers
19k views

I've come across a recurring issue in a few of my recent projects in which I find myself using enums to represent state, or type, or something else, and I need to check against a few conditions. Some ...
anaximander's user avatar
  • 2,295
4 votes
2 answers
6k views

I'm writing a simple chess-related code with intention to write it clearly (performance doesn't matter at all). And this method I have doesn't look clean to me at all: public static Piece ...
vorou's user avatar
  • 153
5 votes
2 answers
615 views

This question is asked on SO and this site often it looks like. "How do I do a dynamic enum?" Answers range from you shouldn't to possible compile time solutions. Now my question is do I want a ...
nportelli's user avatar
  • 285
14 votes
3 answers
10k views

Traditionally, a singleton is usually implemented as public class Foo1 { private static final Foo1 INSTANCE = new Foo1(); public static Foo1 getInstance(){ return INSTANCE; } private ...
irreputable's user avatar
16 votes
8 answers
32k views

I'm an aspiring game developer, I work on occasional indie games, and for a while I've been doing something which seemed like a bad practice at first, but I really want to get an answer from some ...
Bugster's user avatar
  • 4,043
12 votes
4 answers
7k views

I'm making a program that will post data to a database, and I've run into a pattern that I'm sure is familiar: A short table of most-likely (very strongly likely) fixed values that serve as an enum. ...
MPelletier's user avatar
  • 2,068
6 votes
3 answers
7k views

I need to define enums in several classes. The majority of fields are the same in all of the enums. But one has one or two more fields, another has fewer fields. Now I wonder what is the best way to ...
mohsen.d's user avatar
  • 163
5 votes
4 answers
6k views

I have a database table containing a list of systems relevant to the tool I am building, mostly in-house applications, or third-party systems we receive data from. This table is added to infrequently, ...
Niall's user avatar
  • 205
2 votes
2 answers
3k views

I have an enumeration with the commands Play, Stop and Pause for a media player. In two classes I do a switch-case over the received commands. The player runs in a different thread and I deliver the ...
Puckl's user avatar
  • 1,565
13 votes
2 answers
40k views

What is the best practice for packaging Java enums? is it separate file for each enum? or having same file for all the enums? What are the pros and cons ?
goodspeed's user avatar
  • 167
0 votes
1 answer
262 views

I wrote a little app to manage an arbitrary series of tasks (e.g., call a SQL sproc and capture out-vars, run another app, run an SSIS package) with dependencies between tasks. Each task has a status ...
user avatar
7 votes
2 answers
9k views

I stumbled upon this question and a couple of other along the same lines. While we know creation of enum is thread safe and enums are by birth singletons . It kind of confuses me that why would ...
Shahzeb's user avatar
  • 310
23 votes
5 answers
33k views

If I'm using a switch statement to handle values from an enum (which is owned by my class) and I have a case for each possible value - is it worth adding code to handle the "default" case? enum ...
s d's user avatar
  • 352
6 votes
3 answers
34k views

I would like to know how I can use a switch statement with enum values for the following scenarios: I am making a small program for a flight reservation system. The program is meant to enter certain ...
Maxood's user avatar
  • 1,493
1 vote
1 answer
2k views

Which is the currently-accepted best practice in terms of C# enum usage, a bitwise [Flags] Enum (compared using | and &) or an IEnumerable of enum values? I'm thinking both from a code-conciseness ...
Ed James's user avatar
  • 3,499
6 votes
2 answers
2k views

I have this weird scenario in which some Java property is used to build and HQL query, and the type of the field is Boolean, i.e. it is boxed. I wondered why because I don't really like to think of ...
Ionuț G. Stan's user avatar
8 votes
3 answers
4k views

I have seen C code where people used enum heavily. But all it does is confuse others. In many places plain integers can do the same thing with less ambiguity. What are the common misuses of enum?
Gulshan's user avatar
  • 9,542