Our enum type ServerState has an underlying int type.
The possible values for ServerState are defined as case objects. By using Scala’s sealed trait and case object, we can ensure exhaustiveness checking and pattern matching.
By implementing toString, values of ServerState can be printed out or converted to strings.
If we have a value of type Int, we cannot pass it to transition - the compiler will complain about type mismatch. This provides some degree of compile-time type safety for enums.
Transition emulates a state transition for a server; it takes the existing state and returns a new state.
To run the Scala code, save it to a file (e.g., ServerStateExample.scala) and use the Scala compiler to run it:
Now that we can run and build basic Scala programs, let’s learn more about the language.