Default case to the rescue

Report a typo

Your new taste-tester app is coming along nicely, but as it grows larger, you and your team members need to add more and more foods to the taste enum. Unfortunately, one of your team members is a bit forgetful and sometimes adds new items without adding/updating a case statement for them. Fill in the blank with a default case statement so that your code will throw an Exception with the message: "Reminder: please add your new items to a case statement." Use arrow syntax.

int tasteValue = switch (taste) {
    case SUGAR, PIZZA, CHOCOLATE -> 10;
    case MEATBALLS, STEAK -> 7;
    case BROCCOLI -> 4;
    case DIRT -> 1;
    _________________________________
};
Enter a short text
___

Create a free account to access the full topic