It sounds like the assumption behind your question is false. You can switch on enum
values, integer types (char
, int
, byte
, etc.), or String
instances.
Internally, all switches compile to one of two instructions, lookupswitch
or tableswitch
. Both instructions require that each case be labeled with a distinct integer. When you use an enum
value, the "ordinal" of the value is used. When using String
instances, the compiler inserts additional code to map each string to a unique value. Other types are used directly. You can read more about this in another answer.
Methods on an enum
serve the same purpose as methods on any other object. You can use them to implement polymorphic behavior, or as simple accessors, or whatever.