static void shouldSuggestMigratingToPatternMatchingForSwitch()

in java-samples/src/main/java/com/jetbrains/code/jdk21/PatternMatchingForSwitch.java [40:51]


    static void shouldSuggestMigratingToPatternMatchingForSwitch(Object x) {
        if (x instanceof String) {
            System.out.println(x);
        } else if (x instanceof Integer) { // pattern matching for instanceof
            Integer integer = (Integer) x;
            System.out.println(integer + 1);
        } else if (x instanceof List<?> list) {
            System.out.println(list.size());
        } else {
            throw new IllegalArgumentException("Unexpected type: " + x);
        }
    }