Compiling a null case

Report a typo

Will this code compile without the new switch features?

public class SwitchPatternMatchingDemo {
    public static void main(String[] args) {
        String str = null;
        nullDemo(str);
    }

    static void nullDemo(String s) {
        switch (s) {
            case null -> System.out.println("null");
            case "Hi" -> System.out.println("Hi");
            default   -> System.out.println("No Match!");
        }
    }
}
Select one option from the list
___

Create a free account to access the full topic