Tagged Questions

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.

learn more… | top users | synonyms

3
votes
3answers
233 views

How to deal with almost the same enums?

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 ...
5
votes
4answers
181 views

Should I create an Enum mapping to my database table

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, ...
2
votes
2answers
206 views

Is switch-case over enumeration bad practice?

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 ...
1
vote
2answers
176 views

Best practice for packing Java enums?

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 ?
0
votes
1answer
83 views

How far should I expose this status enum?

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 ...
4
votes
2answers
194 views

Why would one ever want to use a synchronized method in Enum?

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 ...
8
votes
5answers
376 views

switch statement - handling default case when it can't be reached

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 ...
5
votes
3answers
473 views

How to use a switch statement with enum efficiently?

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 ...
1
vote
1answer
264 views

Enum with FlagsAttribute or IEnumerable<Enum>/ISet<T>

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 ...
6
votes
2answers
399 views

Java: would you use an EnumSet in this case?

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 ...
3
votes
5answers
298 views

What do you call one element in an enumeration?

The following C# code defines an enumeration. enum MyEnum { alpha, beta, gamma, delta } As a whole it is called an enumeration. What ...
6
votes
3answers
495 views

What are the common misuses of “enum” in C?

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?