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
4 votes
2 answers
1k views

In the title, with namespace-related elements, I refer to Enums, Delegates and other elements that do not belong to a single class, but to the whole namespace, or application. I know that I can cram ...
oneManArmin's user avatar
2 votes
3 answers
640 views

For example, if I use an enum, which all values are manually defined individually, for example: public enum MyNum{ Zero(0), One(1), Two(2); private final int value; MyNum(int ...
ggrr's user avatar
  • 5,893
15 votes
4 answers
8k views

My understanding is that [Flag] enums are typically used for things that can be combined, where the individual values aren't mutually exclusive. For example: [Flags] public enum SomeAttributes { ...
Mathieu Guindon's user avatar
1 vote
2 answers
11k views

Example 1 (used at the moment) If (BodyPart["Right Leg"].BodyStatusEffects["Active"].Active) { BodyPart["Right Leg"].BodyStatusImpacts["Poisoned"].Active = false; BodyPart["Torso"]....
Cold ice programer's user avatar
5 votes
2 answers
3k views

My team is preparing to add new capabilities to an OpenAPI contract and our implementation of it. There are pre-existing clients. We are planning to take our API from v1.1 to v1.2 while fully ...
wberry's user avatar
  • 491
0 votes
1 answer
7k views

I am constructing an enum Flower which contains the fixed set of constants for Flowers as described below. I'm writing it in a separate file and importing it to other classes so that it could be used ...
Tom Taylor's user avatar
0 votes
3 answers
2k views

Regarding enums in java how I understood is Sample enum public enum Strategy { STRATEGY_A { @Override void execute(){ System.out.print("Executing strategy A"); ...
Tom Taylor's user avatar
2 votes
2 answers
934 views

I have an enum with > 10 items each having 8 static properties. Contrived example: enum JavaTypes { INTEGER, BOOLEAN, STRING, ...; boolean isPrimitive() { } boolean ...
billc.cn's user avatar
  • 640
2 votes
1 answer
6k views

I have an ASP.NET Web API application. It uses enums for some fixed sets of states or types. Now I need to extend enum to support more values. But it will break backwards compatibility so I need to ...
Maxim Tkachenko's user avatar
2 votes
2 answers
300 views

I'm working on a piece of software which generates configuration data for certain hardware and currently needs to be adapted each time the hardware is released in a new version by an external company (...
Tim Meyer's user avatar
  • 863
2 votes
2 answers
16k views

I'm doing some code cleanup and I'm looking at my regexes. I have an extremely simple one: (ARA|CHI|FRE|GER|ITA|JPN|RUS|SPA)\s[0-9]{3}-[0-9]{2} It basically validates course identifiers for a ...
Chris Cirefice's user avatar
0 votes
0 answers
277 views

I have some enums in a concrete API/library that will be publicly used by application projects. My problem here, is that I cannot write an interface to these enums (that I know of). I should have ...
Snoop's user avatar
  • 2,758
1 vote
1 answer
92 views

I will illustrate the problem with a specific case. Suppose we have a bit-flag style enumeration type defining different kinds of validations. It's tempting to define an enumerator like ...
Lingxi's user avatar
  • 155
3 votes
3 answers
774 views

I have been experimenting lately with enums, and I found out that in Java they can do much more than simply representing a fixed set of constants. Now, I am thinking about creating a new enum for my ...
carlossierra's user avatar
  • 1,425
33 votes
5 answers
8k views

I was reading some code here and saw that an enum is used to store names of html tags. Why do we ever need to do this? What benefit do I get using this strategy? I know that how useful enums are in ...
CodeYogi's user avatar
  • 2,186
1 vote
2 answers
5k views

Well, I am having two keys and 3 values for that. Say key1,key2,value1,value2,value3. In future may the values can be increased like value4, value5 so on. I need to get the values(value1,value2,...
Jey Ganesh's user avatar
1 vote
0 answers
122 views

I'm making a framework for building simple html websites for an embedded system and I want to make it bulletproof in a way that a user can't make mistakes in building the html document. As I've ...
CodeBreaker's user avatar
1 vote
2 answers
280 views

I am working on a C# class library for my colleagues to use when programming industrial cameras. I'm trying to determine both the most compact and elegant method to write the class. The commands are ...
Norm Schaeffer's user avatar
1 vote
4 answers
308 views

Currently, there are only 3 possible publishers. I might want to add some more in the future: interface NewsArticle { enum Publisher { NYPost, ChiTribune, LATimes } Publisher getPublisher(); ...
konishiki's user avatar
  • 475
2 votes
2 answers
7k views

I have ~30 resources each having ~10 attributes. I want to store some information about each attribute. Ex: its multiplicity, it RW (Read/Write), RO (Read only), longName, shortname. So I was ...
Siddharth Trikha's user avatar
14 votes
1 answer
12k views

I'm currently working on a webapp where we often need to condition some server logic based on the page that is going to be returned to the user. Each page is given a 4-letter page code, and these ...
Joffrey's user avatar
  • 261
4 votes
1 answer
173 views

After reading the answers to this question, and this and this related questions, I'm now confused about how/if to work with an enum having an NxN relationship. Let's say I have an entity Hotel, an my ...
Luis Sep's user avatar
  • 151
99 votes
8 answers
114k views

I've seen a number of questions, like this, asking for advice on how to store enums in DB. But I wonder why would you do that. So let's say that I have an entity Person with a gender field, and a ...
user3748908's user avatar
  • 1,667
7 votes
2 answers
5k views

At work I bumped into a problem to see how enums are growing and storing business logics. As they grew, the constructors grew a lot. At one point I found out instead of putting in let's say the tenth ...
CsBalazsHungary's user avatar
2 votes
1 answer
946 views

We have an enum in a class library: Public Enum FieldType Phone Span Gender DrawPath .... End Enum which we use with an attribute applied to properties, for multiple scenarios: ...
user20416's user avatar
  • 693
2 votes
1 answer
1k views

In the book Effective Java its told that: The basic idea behind Java’s enum types is simple: they are classes that export one instance for each enumeration constant via a public static final field....
vivek's user avatar
  • 473
42 votes
7 answers
52k views

Dilemma I've been reading a lot of best practice books about object oriented practices, and almost every book I've read had a part where they say that enums are a code smell. I think they've missed ...
stromms's user avatar
  • 555
3 votes
2 answers
998 views

I'm reading about Swift enum's in the Swift Programming Language guide and the text was comparing the differences between Swift's enum and C's enum. This made me curious as to where enumerations came ...
Dan Beaulieu's user avatar
70 votes
4 answers
40k views

Suppose I have 4 types of services I offer (they are unlikely to change often): Testing Design Programming Other Suppose I have 60-80 of actual services that each fall into one of the above categories....
Dennis's user avatar
  • 8,267
3 votes
3 answers
3k views

Currently my team has a number of constants defined as static final strings. I want to be able to iterate over these strings as if they were an enum in one location, but everywhere else they are used ...
dsollen's user avatar
  • 1,163
11 votes
3 answers
12k views

Is it an anti-pattern to depend on a particular order of an enum's instance declarations? For example, consider: public enum CompassPoint { North, East, South, West; } These points ...
Bohemian's user avatar
  • 2,076
1 vote
2 answers
3k views

I am developing an application where a user submits a mission and other users accept the mission. Pretty simple. I want to keep a track of the mission progress status and store it into a database. ...
Papa-rapa-beo's user avatar
25 votes
6 answers
49k views

Several times I've seen people use title-case or even all lower-case naming for enum constants, for example: enum Color { red, yellow, green; } This makes working with their string form simple ...
codebreaker's user avatar
  • 1,764
4 votes
1 answer
5k views

I have following problem: need to use enum in my java code, since I'll have to ask in my business logic things like if(someting == enumname.VALUE_ENUM){... but I don't have all the enum types at the ...
Marko Kraljevic's user avatar
3 votes
1 answer
752 views

I am currently reading the Swift language documentation and came across these sentences in the chapter about methods: Similarly, type methods on structures and enumerations can access static ...
TheBaj's user avatar
  • 133
19 votes
5 answers
13k views

Consider the example below. Any change to the ColorChoice enum affects all IWindowColor subclasses. Do enums tend to cause brittle interfaces? Is there something better than an enum to allow for ...
Matthew James Briggs's user avatar
4 votes
3 answers
14k views

I feel like I should be able to find an answer to this, but it turns out to be harder to search than expected... so: In C#, when we do something like: enum MyEnumClass { A, B }; static String Test(...
Hirle's user avatar
  • 300
3 votes
2 answers
1k views

I'm trying to implement a web interface for a user database. Hosts can create guests for their courses, the guests can get deleted after the course has ended but have to remain in the database for a ...
Thaoden's user avatar
  • 151
1 vote
0 answers
307 views

I've inherited an iOS project that uses NS_Enum to store the number of rows and sections in a UITableView At the moment, the UITableView is static; no rows are being added to it. However, that is what ...
narner's user avatar
  • 145
1 vote
0 answers
804 views

I would like to enforce that the elements of a Java Enum are chosen or excluded from an EnumSet at compile time i.e. I am forced to make the decision to put it in the set or not whenever I create a ...
Adam's user avatar
  • 187
1 vote
1 answer
791 views

In Java, an enum is not a plain replacement for a number (like in C/C++), but a family of objects which can have properties. For instance public enum Order { NAME("Ordering by name"), SURNAME("...
SJuan76's user avatar
  • 2,522
5 votes
2 answers
6k views

Let's have a simplified business logic like this: public enum BusinessLogic { STAGE_ONE(true, false, false), STAGE_TWO(true, true, false), STAGE_THREE(false, false, true); private final ...
CsBalazsHungary's user avatar
0 votes
1 answer
623 views

Joshua Bloch claims that "a single-element enumeration type is the best way to implement a singleton" Why? I totally disagree with this statement because enumeration is data type with some type-...
Heisenberg's user avatar
10 votes
3 answers
15k views

I often write code which translates entities in the database to domain objects. These entities often have fields which are constrained and translate to enumerations in the domain objects. In some ...
rory.ap's user avatar
  • 929
2 votes
1 answer
652 views

Why would you use an enum to create a singleton pattern? To what purpose would it serve over a conventional singleton pattern? I have seen the above used. The code uses an enum to create this pattern ...
Mark W's user avatar
  • 131
11 votes
2 answers
10k views

We were having a discussion at my work about the use of enums in Java. A coworker was arguing that when using enums on the server-side, whenever required we should use string to reference to it (for ...
JSBach's user avatar
  • 1,415
1 vote
2 answers
2k views

It seems to me that a lot, if not most, compilers treat enumerated types as int underneath. In C/gcc, enums are compiled to int. In C#/Visual C#, you can change the underlying data type with something ...
Chris Cirefice's user avatar
4 votes
6 answers
16k views

There are times when an enum's values are important: it is not necessary for them to be unique, they also need to have specific values. In such cases, should the values be explicitly defined, even if ...
Paul's user avatar
  • 2,174
1 vote
3 answers
1k views

This is not a very general question, so it may not exactly be appropriate here, but I could sure use a suggestion if you have one: I have an object containing a dictionary keyed off of an enum, ...
kmote's user avatar
  • 3,372
1 vote
2 answers
190 views

For example, if I have two classes "Director" and "Follower". I want the Director to tell the follower where to go (ex: follower1.go(direction.LEFT)), and I want the Director to know what directions ...
Travis's user avatar
  • 343