public class Main {
record R() {}
record S() {}
void test0(Object obj) {
switch (obj) {
case String s:
case Integer i:
System.out.println(i + 1);
default:
}
}
void test1(String s) {
switch (s) {
case "hello":
System.out.println("hello");
case "world":
System.out.println("world");
case String str when str.isEmpty():
System.out.println("an empty string");
case null:
System.out.println("null");
}
}
void test2(Object obj) {
switch (obj) {
case String s:
case R():
case S():
System.out.println(42);
break;
default:
}
}
void test3(Object obj) {
switch (obj) {
case String s:
default:
System.out.println(42);
}
}
void test4(Object obj) {
switch (obj) {
case null:
case String s:
System.out.println(s);
default:
}
}
void test5(String s) {
switch (s) {
case null:
case "hello":
System.out.println("hello");
break;
default:
}
}
void test6(Object obj) {
switch (obj) {
case S():
case null:
case R():
System.out.println("blah blah blah");
break;
default:
}
}
void test7(Object obj) {
switch (obj) {
case String s:
System.out.println(s);
case R():
System.out.println("It's either an R or a string");
break;
default:
}
}
void test8(Object obj) {
switch (obj) {
case String s:
System.out.println("String: " + s);
case Integer i:
System.out.println(i + 1);
default:
}
}
void test9(Object obj) {
switch (obj) {
case R():
case S():
System.out.println("Either R or an S");
break;
default:
}
}
void test10(Object obj) {
switch (obj) {
case null:
case R():
System.out.println("Either null or an R");
break;
default:
}
}
void test11(Integer integer) {
switch (integer) {
case 1, 2:
case null, Integer i when i == 42:
System.out.println("blah blah blah");
break;
default: System.out.println("null");
}
}
void test12(Integer integer) {
switch (integer) {
case 1, 2, Integer i1 when i1 > 5:
case null:
System.out.println("blah blah blah");
break;
default:
}
}
void test13(Object obj) {
switch (obj) {
case String s, null -> {}
default -> {}
}
}
void test14(Object obj) {
switch (obj) {
case null, String s when s.isEmpty(), Integer i when i == 42 -> {}
default -> {}
}
}
void test15(Object obj) {
switch (obj) {
case String s when s.isEmpty(), null, Integer i -> {}
default -> {}
}
}
void test16(Object obj) {
switch (obj) {
case String s, Integer i, null -> {}
default -> {}
}
}
void test17(String s) {
switch (s) {
case null, "hello", "world" -> {}
default -> {}
}
}
void test18(String s) {
switch (s) {
case "hello", "world", null, String str when str.isEmpty() -> {}
default -> {}
}
}
void test19(String s) {
switch (s) {
case "hello", "world", null, String str -> {}
}
}
void test20(Object obj) {
switch (obj) {
case null, S(), R() -> {}
default -> {}
}
}
void test21(Object obj) {
switch (obj) {
case S(), null, R() -> {}
default -> {}
}
}
void test22(Object obj) {
switch (obj) {
case String s when s.isEmpty(), null, Integer i -> {}
default -> {}
}
}
void test23(Object obj) {
switch (obj) {
case String s, Integer i, null -> {}
default -> {}
}
}
void test24(String s) {
switch (s) {
case "hello", "world", null, String str -> {}
}
}
void test25(String s) {
switch (s) {
case "hello", "world", String str, null -> {}
}
}
void test26(Object obj) {
switch (obj) {
case String s:
case null:
System.out.println(s);
default:
throw new IllegalStateException("Unexpected value: " + obj);
}
}
void test27(Object obj) {
switch (obj) {
case String s:
System.out.println(s);
case null:
System.out.println(s);
default:
throw new IllegalStateException("Unexpected value: " + obj);
}
}
void test28(Object obj) {
switch (obj) {
case Integer i, String str -> {}
default -> {}
}
}
void test28(String s) {
switch (s) {
case String str, "hello", "world" -> {}
}
}
void test29(Object obj) {
switch (obj) {
case null, default -> {}
}
}
void test30(Object obj) {
switch (obj) {
case default, null -> {}
}
}
void test31(Object obj) {
switch (obj) {
case String s, default -> {}
}
}
void test32(String s) {
switch (s) {
case "hello", "world", default -> {}
}
}
void test33(String s) {
switch (s) {
case default -> {}
}
}
}