The possible values for ServerState are defined as constants. By using an enum class, each state is explicitly declared.
By implementing the toString method, the states can be printed out or converted to strings. Here is how you can achieve that in Kotlin:
If we have a value of type int (or Integer in Kotlin), we cannot directly pass it to functions expecting ServerState without explicit conversion. This provides some degree of compile-time type safety for enums.
To run the program, you can compile and execute it using Kotlin’s command-line tools or IDE support.
Now that we can run and build basic Kotlin programs, let’s learn more about the language.