3 ms·
Coming from C and areas where C is used, enums tend to used with values defined explicitly because they usually don't represent an abstract set but indeed speci
by mytailorisrich 6y ago
Coming from C and areas where C is used, enums tend to used with values defined explicitly because they usually don't represent an abstract set but indeed specific values that have to be respected.
An example at random from a domain Go is used a lot in (networking): When you define an enum of the resources recors in DNS you want the values to match the RFC definitions as they are used in DNS packets.
With that in mind Go's approach to enums makes sense: we usually want to label explicit values, potentially of an explicit type, we don't just want an abstract semantic label.
I haven't touched Java in a long time, but as far as I recall low-level operations on fields, bitmaps, etc. were not a strong point.
- tsimionescu 6y agoSure, there is value in having your enums have specific values, but even in C they at least get a bit of namespacing. And yes, Java enums are very verbose if you want to use them for low-level operations, but that is almost entirely the fault of the rest of Java and not enums themselves specifcally.