< prev index next >

test/langtools/tools/javac/switchextra/SwitchStatementBroken.java

Print this page
rev 56806 : 8232684: Make switch expressions final
Reviewed-by: TBD
   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986
   4  * @summary Verify that rule and ordinary cases cannot be mixed.
   5  * @compile/fail/ref=SwitchStatementBroken.out -XDrawDiagnostics --enable-preview -source ${jdk.version} SwitchStatementBroken.java
   6  */
   7 
   8 public class SwitchStatementBroken {
   9 
  10     private void statementBroken(int i) {
  11         String res;
  12 
  13         switch (i) {
  14             case 0 -> { res = "NULL-A"; }
  15             case 1: { res = "NULL-A"; break; }
  16             case 2: { res = "NULL-A"; break; }
  17             default -> { res = "NULL-A"; break; }
  18         }
  19     }
  20 
  21 }
   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986
   4  * @summary Verify that rule and ordinary cases cannot be mixed.
   5  * @compile/fail/ref=SwitchStatementBroken.out -XDrawDiagnostics SwitchStatementBroken.java
   6  */
   7 
   8 public class SwitchStatementBroken {
   9 
  10     private void statementBroken(int i) {
  11         String res;
  12 
  13         switch (i) {
  14             case 0 -> { res = "NULL-A"; }
  15             case 1: { res = "NULL-A"; break; }
  16             case 2: { res = "NULL-A"; break; }
  17             default -> { res = "NULL-A"; break; }
  18         }
  19     }
  20 
  21 }
< prev index next >