jdk-24/test/langtools/tools/javac/patterns/CaseDefault.java
Jan Lahoda 908aca29ca 8262891: Compiler implementation for Pattern Matching for switch (Preview)
Co-authored-by: Brian Goetz <briangoetz@openjdk.org>
Co-authored-by: Mandy Chung <mchung@openjdk.org>
Co-authored-by: Jan Lahoda <jlahoda@openjdk.org>
Reviewed-by: mcimadamore, forax, godin, psandoz, mchung
2021-06-07 07:01:30 +00:00

38 lines
1.0 KiB
Java

/*
* @test /nodynamiccopyright/
* @bug 8262891
* @summary Check null handling for non-pattern switches.
* @compile/fail/ref=CaseDefault.out -source 16 -Xlint:-options -XDrawDiagnostics CaseDefault.java
* @compile --enable-preview -source ${jdk.version} CaseDefault.java
* @run main/othervm --enable-preview CaseDefault
*/
public class CaseDefault {
public static void main(String[] args) {
new CaseDefault().run();
}
void run() {
String str = "other";
switch (str) {
case "a": throw new AssertionError("Wrong branch.");
case default: break; //OK
}
switch (str) {
case "a" -> throw new AssertionError("Wrong branch.");
case default -> {} //OK
}
int i;
i = switch (str) {
case "a": throw new AssertionError("Wrong branch.");
case default: yield 0; //OK
};
i = switch (str) {
case "a" -> throw new AssertionError("Wrong branch.");
case default -> 0; //OK
};
}
}