Attempting to perform a swtich when on a string variable results in the following compilation error:
'when identifier' is only allowed for switch on enum
To work around this the developer needs to code literal string values into the when statements. This makes sense, as the compiler needs to verify the conditional value at compile time and not permit changes to the condition at runtime.
However, if the variable was modified with the final
keywords it could still meet these criteria required by the compiler without forcing the developer to repeat strings or change to an enum.