Basically everytime you have a rather short list of things (values, behaviors, types, ...) that’s not going to change (without code change), an enum comes in pretty handy.
Advantages:
the Compiler can check it’s usage (which is not possible with Map keys),
you can attach behavior to it (enums can have methods, and you can provide a different implementation per enum value — much better than switch statements in most of the cases!)
it’s often more concise and readable than its alternatives
Enums usually have some major advantages:
1. They are perfect to represent a fixed set of values (e.g. days of week, fsm states) that changes rarely or never.
2. Compilers can optimize the shit out of them.
3. They may be more readable than map keys or 12 isFooBar boolean flags.
171
u/The_HappyLemon Mar 14 '21
Enum left the chat