< prev index next >

test/langtools/tools/javac/switchexpr/ExpressionSwitchUnreachable.java

Print this page


   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986
   4  * @summary Verify reachability in switch expressions.
   5  * @compile/fail/ref=ExpressionSwitchUnreachable.out -XDrawDiagnostics --enable-preview -source 12 ExpressionSwitchUnreachable.java
   6  */
   7 
   8 public class ExpressionSwitchUnreachable {
   9 
  10     public static void main(String[] args) {
  11         int z = 42;
  12         int i = switch (z) {
  13             case 0 -> {
  14                 break 42;
  15                 System.out.println("Unreachable");  //Unreachable
  16             }
  17             default -> 0;
  18         };
  19         i = switch (z) {
  20             case 0 -> {
  21                 break 42;
  22                 break 42; //Unreachable
  23             }
  24             default -> 0;
  25         };


   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986
   4  * @summary Verify reachability in switch expressions.
   5  * @compile/fail/ref=ExpressionSwitchUnreachable.out -XDrawDiagnostics --enable-preview -source 13 ExpressionSwitchUnreachable.java
   6  */
   7 
   8 public class ExpressionSwitchUnreachable {
   9 
  10     public static void main(String[] args) {
  11         int z = 42;
  12         int i = switch (z) {
  13             case 0 -> {
  14                 break 42;
  15                 System.out.println("Unreachable");  //Unreachable
  16             }
  17             default -> 0;
  18         };
  19         i = switch (z) {
  20             case 0 -> {
  21                 break 42;
  22                 break 42; //Unreachable
  23             }
  24             default -> 0;
  25         };


< prev index next >