Switch expressions enforce coverage of all enum values or require a default case.
In Java 17, switch expressions require you to cover all possible values of an enum, or alternatively, include a default case. This prevents runtime errors due to missing cases. For instance, when handling order statuses, defining cases for each enum value or specifying a default ensures that no scenario is missed: 'switch (status) { case PENDING -> "Waiting"; case SHIPPED -> "On the way"; case DELIVERED -> "Arrived"; }'.
Additional Notes
How do switch expressions in Java 17 ensure exhaustive handling of enum values?