You shouldn’t depend on the int value of an enum , only on its actual value. Enums in Java are a different kind of monster and are not like enums in C, where you depend on their integer code. Regarding the example you provided in the question, Font. PLAIN works because that’s just an integer constant of the Font class.
Read moreCan enum have int values?
Since Enums can be any integral type ( byte , int , short , etc.) , a more robust way to get the underlying integral value of the enum would be to make use of the GetTypeCode method in conjunction with the Convert class: enum Sides { Left, Right, Top, Bottom } Sides side = Sides.
Read moreShould enums be string or int?
Therefore, go for the meaning : the Strings are more meaningful than numbers, so use the String . Show activity on this post. Both have advantages. If you store them by their Integer value, then you must be careful editing your enumeration later on in your project.
Read moreCan enum values be strings?
Every enum has both a name() and a valueOf(String) method . The former returns the string name of the enum, and the latter gives the enum value whose name is the string.
Read moreCan I store string in enum?
Enum constants can only be of ordinal types ( int by default), so you can’t have string constants in enums .
Read moreHow do I assign a string value to an enum?
Parse the string value into an Enum Enum. Parse(Type enumType,string value) – This method directly parses the string representation of the name or numeric value of enum member into enumType object. If the string representation of the name is not found, then it will give the exception.
Read more