|
Previously I've defined enumerated types that are intended to be private in the header file of the class.
private: enum foo { a, b, c };
However, I don't want the details of the enum exposed anymore. Is defining the enum in the implementation similar ...
Started by Anonymous on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The following will be possible in C++0x:
// foo.h class foo { enum bar : int; // must specify base type bar x; //....
C++ doesn't have forward declarations of enums, so you can't separate enum "type" from enum "implementation".
|
|
I have the following enum
public enum myEnum { ThisNameWorks, This Name doesn't work Neither.does.this; }
Is it not possible to have enums with "friendly names" ?
Thanks
Started by JL on
, 12 posts
by 12 people.
Answer Snippets (Read the full thread at stackoverflow):
I still consider the first one to ....
Enum names live under...
Enum value names must follow the same naming rules as normal variables in C#, therefore only first name is correct.
What you are suggesting would be very bad practice anyway .
|
|
I have enumeration like this:
public enum Configuration { XML(1), XSLT(10), TXT(100), HTML(2), DB(20); private final int id; private Configuration(int id) { this.id = id; } public int getId() { return id; } }
Sometimes I need to check how many fields ...
Started by mykhaylo on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
If you only need the size, I'd just use:
private static final in, which is just the size of the enum - the fact that you get at it through an array of values.
I wouldn't hard-code it though...
Copying.
|
Ask your Facebook Friends
|
I am trying to think of an elegant way to solve this problem in Java:
Given an int of 0-100 what is an elegant way to turn it into an enum where each of the enum's possible values correspond to a range of ints.
For example
enum grades{ A -> 90-95% ...
Started by Benju on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Below is an example,
private static final Map<Integer, Grade> GRADE_MAP){ return GRADE_MAP.get(percent); }
I'd make....
Public enum Grade { A(100, 90), B(89, 80), C(79, 70); int uBound; int lBound; Grade(int uBound, int in this case.
|
|
I want to override toString() for my enum, Color . However, I can't figure out how to get the value of an instance of Color inside the Color enum. Is there a way to do this in Java?
Example:
public enum Color { RED, GREEN, BLUE, ... public String toString...
Started by Matthew on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Add a getAbbreviation() and use that instead of .toString()
public enum Color { RED("R"), GREEN("G"), BLUE("B"); private final String str; private Color(String s){ str = s; } public String toString and String.substring() :
public....
|
|
Given the following java enum:
public enum AgeRange { A18TO23 { public String toString() { return "18 - 23"; } }, A24TO29 { public String toString() { return "24 - 29"; } }, A30TO35 { public String toString() { return "30 - 35"; } }, }
Is there any way...
Started by Walter on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Public enum AgeRange; }
Or, as others....
This:
public enum AgeRange { A18TO23 ("18-23"), A24TO29 ("24-29"), A30TO35("30-35"); private String to override valueOf() to translate the output of toString() back to the Enum values.
|
|
I'm trying to lookup against an Enum set, knowing that there will often be a non-match which throws an exception: I would like to check the value exists before performing the lookup to avoid the exceptions. My enum looks something like this:
public enum...
Started by davek on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
private static final Map<String, Fruit> lookup....
Public enum Fruit { APPLE("apple"), ORANGE("orange"); // Order of initialisation might need adjusting, I haven't tested it.
When I do this I usually graft it onto my enum class.
|
|
Hi. Is there a way I could point an Enum to another Enum? Here are the needs and details:
Currently:
I have a two public classes com.abcd.MyManager and com.abcd.data.MyObject. MyObject class have pretty much everything is private except Types enum member...
Started by Sha Le on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
If you really want to have the enum inside MyManager , then MyObject must refer attempt the refactoring?
You can have....
The enum to com.abcd.Types , and make sure the MyObject code file includes a using directive for the com.abcd namespace.
|
|
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 final int RETINOL = 0; public static final int ...
Started by jpdaigle on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
This needn't be a wholesale overnight change; for example, you could expose... .
Wait for the next major revision, change everything to enum and provide a script (sed, perl, Java is likely, then NutrientType should probably become an enum .
|
|
Is there a way to get around the class-loading issues caused by having two enums that reference each other?
I have two sets of enumerations, Foo and Bar, defined like so:
public class EnumTest { public enum Foo { A(Bar.Alpha), B(Bar.Delta), C(Bar.Alpha...
Started by Sbodd on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Etc } }
for each enum? It looks like you have some overlapping responses in your example.
Public enum Foo { A, B, C; setResponse(Bar b) { this.b = b; } public final Bar b; } static Bar.Alpha; // ...
|