< prev index next >

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

Print this page


   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8212982
   4  * @summary Verify a compile-time error is produced if switch expression does not provide a value
   5  * @compile/fail/ref=ExpressionSwitchFlow.out --enable-preview -source 12 -XDrawDiagnostics ExpressionSwitchFlow.java
   6  */
   7 
   8 public class ExpressionSwitchFlow {
   9     private String test1(int i) {
  10         return switch (i) {
  11             case 0 -> {}
  12             default -> { break "other"; }
  13         };
  14     }
  15     private String test2(int i) {
  16         return switch (i) {
  17             case 0 -> {
  18             }
  19             default -> "other";
  20         };
  21     }
  22     private String test3(int i) {
  23         return switch (i) {
  24             case 0 -> {}
  25             default -> throw new IllegalStateException();


   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8212982
   4  * @summary Verify a compile-time error is produced if switch expression does not provide a value
   5  * @compile/fail/ref=ExpressionSwitchFlow.out --enable-preview -source 13 -XDrawDiagnostics ExpressionSwitchFlow.java
   6  */
   7 
   8 public class ExpressionSwitchFlow {
   9     private String test1(int i) {
  10         return switch (i) {
  11             case 0 -> {}
  12             default -> { break "other"; }
  13         };
  14     }
  15     private String test2(int i) {
  16         return switch (i) {
  17             case 0 -> {
  18             }
  19             default -> "other";
  20         };
  21     }
  22     private String test3(int i) {
  23         return switch (i) {
  24             case 0 -> {}
  25             default -> throw new IllegalStateException();


< prev index next >