import java.util.Random; class EnhancedSwitchStatements { static final int FI = 4; enum E { E1, E2 } void m(String... args) { String count; switch (args.length) { case 0 -> throw new IllegalStateException("no args"); case 1 -> count = "one"; default -> { count = "many"; } } switch (new Random().nextInt()) { case 0 -> throw new IllegalStateException("no args"); break; } switch (new Random().nextInt()) { case 0 -> throw new IllegalStateException("no args"); case 1: break; } switch (new Random().nextInt()) { case 0: throw new IllegalStateException("no args"); break; case 1 -> { System.out.println("one"); } } { case 11 -> System.out.println("hi there"); } { default -> System.out.println("hi there"); } switch (new Random().nextInt()) { case 42 -> "bingo"; } switch (new Random().nextInt()) { default -> noop(); case 1 -> noop(); default -> noop(); } switch (new Random().nextInt()) { case FI/2 - 1 -> noop(); case (1 + 35/16) % 2 -> noop(); case FI - 8 -> noop(); } final byte b = 127; switch (new Random().nextInt()) { case b -> System.out.println("b=" + b + ";"); case 127 -> System.out.println("sweet spot"); } switch (0) { case 0 -> noop(); case "\410" == "!0" ? 1 : 0 -> noop(); case "" == "" + "" ? 3 : 0 -> noop(); } switch (E.valueOf("E1")) { case E1 -> noop(); } switch (E.valueOf("E1")) { case E1 -> noop(); case E2 -> noop(); case null -> noop(); } switch (E.valueOf("E1")) { case E.E1 -> noop(); case E2 -> noop(); case 1 -> noop(); } switch (new Random().nextInt()) { case 1, 1 -> noop(); } switch (new Random().nextInt()) { case 1, 2: noop(); break; case 3, 2: noop(); break; } switch (new Object()) { } } private static void noop() { } }