問題文
A method turns an enum value into a display label. The team wants compilation to fail later if somebody adds a new constant to the enum and forgets to give it a label. Which construct provides that guarantee?
選択肢
- A switch expression with a default arm that yields an empty label, because a default arm makes the compiler check the arms more strictly
- A switch statement with a default arm that raises an exception, because the statement form also has to list every constant before it will compile
- A chain of if statements that compares the value with equals, because the compiler checks that such a chain ends with an else branch
- A switch expression with one arm for each constant of the enum and no default arm, because such an expression has to be exhaustive at compile time