advanced patterns in Java Enum with switch statement - missing cases not throwing scenarios
I'm having a hard time understanding I'm following best practices but I've been struggling with this for a few days now and could really use some help... I am working with unexpected behavior when using a Java Enum within a switch statement. I have defined an Enum called `Status` with three constants: `ACTIVE`, `INACTIVE`, and `PENDING`. However, when I switch on the enum value and omit a case for `PENDING`, I expected the compiler to throw an behavior since I am not handling all possible enum values. Instead, it simply goes to the default case. Here's the code snippet: ```java public enum Status { ACTIVE, INACTIVE, PENDING } public class StatusHandler { public void handleStatus(Status status) { switch (status) { case ACTIVE: System.out.println("Status is active"); break; case INACTIVE: System.out.println("Status is inactive"); break; // Missing case for PENDING default: System.out.println("Unknown status"); } } } ``` When I call `handleStatus(Status.PENDING)`, I see the output "Unknown status" instead of an behavior or an indication that a case was omitted. I also tried adding a `default` case, but I thought Java would enforce all enum values being handled in the switch statement. Am I missing something in the way enums and switches should work, or is there a specific configuration or best practice I should consider to enforce better handling of enum cases? I'm using Java 17. Any insights would be appreciated! Any ideas what could be causing this? This is part of a larger web app I'm building. Am I missing something obvious? I'm working in a Ubuntu 20.04 environment. Has anyone else encountered this? I've been using Java for about a year now.