enums

Java's enum... Where are they created?

Hi all, Since enum in C# are on the stack, I was wondering where enum, in Java, where created. On the stack? On the heap? In some mysterious other place? Enumeration in C# are more primitive than those in Java, this might explain why they are created on the stack... Where are they? I can't find them! Thanks ...

Java Enums find enum.

Hello, I've just read tutorial about enums and have one question. I've studied example: public enum Planet { MERCURY (3.303e+23, 2.4397e6), VENUS (4.869e+24, 6.0518e6), EARTH (5.976e+24, 6.37814e6), MARS (6.421e+23, 3.3972e6), JUPITER (1.9e+27, 7.1492e7), SATURN (5.688e+26, 6.0268e7), URANUS (8.686...

Why can't enum constructors be protected or public in Java?

The whole question is in the title. For example: enum enumTest { TYPE1(4.5, "string1"), TYPE2(2.79, "string2"); double num; String st; enumTest(double num, String st) { this.num = num; this.st = st; } } The constructor is fine with the default or private modifier, b...

Most efficient way to parse a flagged enum to a list

I have a flagged enum and need to retrieve the names of all values set on it. I am currently taking advantage of the enum's ToString() method which returns the elements comma-separated. public void SetRoles(Enums.Roles role) { IList<Entities.Role> roleList = role.ToString("G").Split(',') .Select(r => new Ent...

how can I use an enum to replace several fields? How can I pass these values to an interface?

I have a class which 4 fields which I need to be able to set and get. I have to use setters and getters, but also instead of using regular fields, have to use an enum. This concept confuses me - considering the fields arent necessarily constants. I'll give an example If we call the class Bear, the 4 fields may be: name, type, nickname, ...

WPF - binding enum type to textbox

Hi I bind textbox.text value to enum type. My enum looks like that public enum Type { Active, Selected, ActiveAndSelected } What I wan't to acomplish is to show on textbox "Active Mode" instead of "Active" and so on. Is it possible to do that? It would be great if I could acomplish that in XAML - be...

Working with enums(constructing a list)

Hi guys, You may have run into situations wherein you declare a certain enum and you want to evaluate a certain object to find out which enum categories it satisfies i.e an object may satisfy the conditions for it to be classified into more than one enum. An example would be, say in an university i have various Course and this has the...

DragDropEffects.Scroll: why -2147483648 not 8?

A standard enumeration in System.Windows.Forms: [Flags] public enum DragDropEffects { Scroll = -2147483648, // // Summary: // The combination of the System.Windows.DragDropEffects.Copy, System.Windows.Forms.DragDropEffects.Link, // System.Windows.Forms.DragDropEffects.Move, and System.Windows.Forms.DragDropEf...

mvc.net how to populate dropdownlist with enum values

I have an enum for one of the properties of my view-model. I want to display a drop-down list that contains all the values of the enum. I can get this to work with the following code. What I'm wondering is whether there is a simple way to convert from an enum to an IEnumerable? I can do it manually as in the following example, but wh...

JAXB + Enums + Showing Multiple Values

I have an enum: @XmlEnum @XmlRootElement public enum Product { POKER("favourite-product-poker"), SPORTSBOOK("favourite-product-casino"), CASINO("favourite-product-sportsbook"), SKILL_GAMES("favourite-product-skill-games"); private static final String COULD_NOT_FIND_PRODUCT = "Could not find product: "; private...

Benefits of using enums over directly using integral types?

1) I’m aware of the following benefits: they increase the level of abstraction since you immediately see what underlying integral values represent. You can use them instead of magic numbers and by doing that making the code more understandable They also restrict the values an enum variable can have and in doing so make the application ...

In switch statement can we use enum in C#

Suppose we want to give condition using switch statement with the use of enum. Can we do that? If yes, then how? ...

Persist enum with business value with hibernate annotations.

I have enum ClientType{INTERNAL,ADMIN}, i am able to persist enum with hibernate annotations. but inserted value is INTERNAL,ADMIN. How can i define my own vlaue. I want table to contain "I" for INTERNAL. How can i do this hibernate annotations. ...

Is there another way to test Enum bit fields?

When using Enums with bit fields: enum ReallyBigEnum { FirstChoice = 0x01, AnotherOption = 0x02 } ReallyBigEnum flag = ReallyBigEnum.FirstChoice | ReallyBigEnum.AnotherOption; the code used to test the bits is: if( (flag & ReallyBigEnum.AnotherOption) == ReallyBigEnum.AnotherOption ) { ... } which seems verbose and erro...

How can I use C++ enum types like C# ?

How can I use C++ enum types like C# ? consider following definition in c++ : enum myEnum { A, B, C}; myEnum en = A; Now I want write line #2 as following line like C# : myEnum en = myEnum.A; ?? ...

Java: instantiating an enum using reflection

Hello, Suppose you have a text file like: my_setting = ON some_method = METHOD_A verbosity = DEBUG ... That you wish to to update a corresponding object accordingly: Setting my_setting = ON; Method some_method = METHOD_A; Verbosity verbosity = DEBUG; ... Where all are different kind of enums. I would like to have a generic way to...

Java de-serialization of enums and valueOf

I've got a distributed system with a serializable enum class with constants that might vary across the system. Because these classes may be different, valueOf could potentially be called upon deserialization on a constant that doesn't exist, throwing a runtime exception. I don't believe valueOf can be overridden, or another method cu...

Should I use an enum or multiple const for non-sequential constants in c++?

I'm writing porting file-io set of functions from c into a c++ class. "Magic numbers" (unnamed constants) abound. The functions read a file header which has a number of specific entries whose locations are currently denoted by magic numbers. I was taught by a veteran programmer a couple years back that using "magic numbers" is inher...

problem regarding assigning numbers to an enum variable.

Hello there, I've created a simple enum in C# as follows enum Direction { North, South, East, West } Now I'm creating a variable of this Direction enum as : Direction D = (Direction)3; Console.WriteLine(D.ToString()); Every thing goes fine and code works as expected and gives the following as output. West but no...

Other method for iterating an enum

Initially I had the following: [Flags] public enum QueryFlag { None = 0x00, CustomerID = 0x01, SalesPerson = 0x02, OrderDate = 0x04 } As check boxes are checked/unchecked, I would add/remove flags from: QueryFlag qflag; My idea - when the user clicks the Search button, I would iterate the actual flags set in qflag t...