< prev index next >

test/langtools/tools/javac/switchexpr/SwitchExpressionScopesIsolated.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 scopes in rule cases are isolated.
   5  * @compile/fail/ref=SwitchExpressionScopesIsolated.out -XDrawDiagnostics --enable-preview -source ${jdk.version} SwitchExpressionScopesIsolated.java
   6  */
   7 
   8 public class SwitchExpressionScopesIsolated {
   9 
  10     private String scopesIsolated(int i) {
  11         return switch (i) {
  12             case 0 -> { String res = ""; yield res; }
  13             case 1 -> { res = ""; yield res; }
  14             default -> { res = ""; yield res; }
  15         };
  16     }
  17 
  18 }
   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986
   4  * @summary Verify that scopes in rule cases are isolated.
   5  * @compile/fail/ref=SwitchExpressionScopesIsolated.out -XDrawDiagnostics SwitchExpressionScopesIsolated.java
   6  */
   7 
   8 public class SwitchExpressionScopesIsolated {
   9 
  10     private String scopesIsolated(int i) {
  11         return switch (i) {
  12             case 0 -> { String res = ""; yield res; }
  13             case 1 -> { res = ""; yield res; }
  14             default -> { res = ""; yield res; }
  15         };
  16     }
  17 
  18 }
< prev index next >