A switch expression can be used to return a value or just execute a set of statements, like the traditional switch statement.
When you are using a switch expression to return a value that is used to assign a value to a variable, its cases must be exhaustive. This essentially means that, whatever value you pass to the switch argument, it must be able to find an appropriate branch to execute. A switch expression can accept arguments of the byte, short, int, Byte, Short, Integer, or String types or enums. Of these, only an enum has exhaustive values.
In the following example, a switch expression is being used to assign a value to the damage variable. Since there is no matching branch to execute for the PLATE value, this code won't compile:
class Planet { private static long damage; public void use(SingleUsePlastic plastic) { damage += switch...