Using Automatic Values, Aliases, and Unique Values
auto() assigns consecutive integer numbers to each
Enum member starting from one. You can tweak this default behavior by overriding the methods seen on screen, which
auto() uses under the hood to generate the automatic values.
02:10 However, they share a common kernel called Linux. These enumerations map operating systems to their corresponding kernels. This relationship turns Debian into an alias of Ubuntu, which may be useful when you have code that’s kernel related, along with code that’s specific to a given Linux distribution.
An important piece of behavior to note in this example is when you iterate over the
Enum directly, aliases aren’t considered. If you ever need to iterate over all the members, including aliases, then you need to use
03:22 Here the exception message points out that Debian and Ubuntu share the same value, which is not allowed. Up to this point, you’ve learned what enumerations are, when to use them, and what benefits you get from using them in your code.
Become a Member to join the conversation.