enum « Integer « Java Data Type Q&A





1. What's the best way to handle coexistence of the "int enum" pattern with java enums as an API evolves?    stackoverflow.com

Suppose you're maintaining an API that was originally released years ago (before java gained enum support) and it defines a class with enumeration values as ints:

public class VitaminType {
 public static ...

2. Emulate C++ enum integer with Java Enums    stackoverflow.com

I'm attempting to translate some C++ code into Java. I'm looking for the best way to emulate this type of C++ paradigm in Java -- I think enums are probably ...

3. Java - shift int enums    stackoverflow.com

In C, I sometimes used structures such as

enum {
   UIViewAutoresizingNone                 = 0,
 ...

4. Convert integer value to matching Java Enum    stackoverflow.com

I've an enum like this:

public enum PcapLinkType {
  DLT_NULL(0)
  DLT_EN10MB(1)
  DLT_EN3MB(2),
  DLT_AX25(3),
  /*snip, 200 more enums, not always consecutive.*/
  DLT_UNKNOWN(-1);
    private final ...

5. Cast Int to enum in Java    stackoverflow.com

What is the correct way to cast an Int to an enum in Java given the following enum?

public enum MyEnum
{
    EnumValue1,
    EnumValue2
}


MyEnum enumValue = (MyEnum) ...

6. Setting an enum by using an int specific to that enum?    stackoverflow.com

Hey all. So I have a set of enums and a db with integers corresponding to those enums. Something like this, for example:

public static enum Day {
    SUNDAY(1), ...

7. Simple Integer Enum    stackoverflow.com

I'm new with enums and I'd like to create one to compare an integer to a more comprehensible definition.

if (getFruit() == myEnum.APPLE) {
    // ...
}
instead of
if (getFruit() == ...

8. Using integer in enumerated type     stackoverflow.com

I am trying to declare this enum:

public enum Month {
    1, 2, 3, 4, 5 , 6, 7, 8, 9, 10, 11, 12;
}
But when I try to compile ...

9. how can i get set integer, string value from my Enum in Java?    stackoverflow.com

How can i pre-define any types of values in the Enum?

public enum Hardware
{
    USB2(0) = "external low speed",
    PCI(1)  = "embedded",
    ...





10. How to convert enum value to int?    stackoverflow.com

I have a function which return a type int. However, I only have a value of the TAX enumeration. How can I cast the TAX enumeration value to an int?

public enum TAX ...

11. declaring an enum based on an int?    coderanch.com

I thank you genelemen. I see what you both have done. I think the map solution is better suited to larger enums, while, for what I'm doing, less than 10 or so values, the loop (which is basically a linear search vs. whatever the map uses [b-tree?]) is more appropriate. I think that's the fundamental difference. Agree? One thing I didn't ...

12. cast int to an enum    coderanch.com

13. Enum or int    coderanch.com

Hi All I have a question which is actuall a "design" question. I am creating a small game, and now working on the Attack class. basically it has couple of attributes there which are all int values (representing attack power, attack pp and so on..) and do not matter for my question. However, I want to have a member to indicate ...

14. "casting" an int to an enum type    coderanch.com

Enum types in Java provide an ordinal() method to supply the int value associated with a particular enum value. I'd like to go in the other direction, "casting" an int value to a corresponding enum. Of course, Java won't let me do an actual cast. The only suggestion I've seen on how to accomplish this is by setting up an array ...

15. Assigning enum a integer value    forums.oracle.com

hellow, please is there any way to assign items of enum type a integer value. I have enum SizeOfGrid { 9x9, 16x16, 25x25, ... } and i need to assign an integer value to each items so i can create new grids like new Grid(9x9.value) or something and not using switch each time like: Switch(sizeOfGrid) { case 9x9: { value = ...

16. int to Enum    forums.oracle.com





17. int to enum question    forums.oracle.com

Enums are in general about as complex as constant ints, though they can be made more complex if you chose to do so. The point of using an enum, however, is not to reduce complexity, but to provide value safety. If you use the enum values, then at compile time, you can only provide FOO, BAR, and BAZ, and anything else ...