Details
-
New Feature
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
In switch pattern matching, the error "the switch statement does not cover all possible input values" is thrown in the given case :
static void error2(Object o1) { switch (o1) { case null -> System.out.println("null case"); case Integer i && i > 0 -> System.out.println("2nd case"); // Positive integer cases case Integer i -> System.out.println("3rd case" + i); // All the remaining integers } }
The IDE can give a hint for the switch expression for adding a default to the switch statement/expression which will fix the error as given below :
static void error2(Object o1) { switch (o1) { case null -> System.out.println("null case"); case Integer i && i > 0 -> System.out.println("2nd case"); // Positive integer cases case Integer i -> System.out.println("3rd case" + i); // All the remaining integers default -> throw new IllegalStateException("Unexpected value: " + o1); } }