For when()
to be used as an expression, it needs to be "exhaustive", guaranteeing
that there is a branch for each possible situation. Frequently, this means you need
an else
branch.
However, with enum
, we know all possible values up front. So, if you have a branch
for each enum
constant, you will not need an else
branch.
You can learn more about this in:
Tags: