< prev index next >

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

Print this page
rev 56806 : 8232684: Make switch expressions final
Reviewed-by: TBD
   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986 8222169 8224031
   4  * @summary Check expression switch works.
   5  * @compile/fail/ref=ExpressionSwitch-old.out -source 9 -Xlint:-options -XDrawDiagnostics ExpressionSwitch.java
   6  * @compile --enable-preview -source ${jdk.version} ExpressionSwitch.java
   7  * @run main/othervm --enable-preview ExpressionSwitch
   8  */
   9 
  10 import java.util.Objects;
  11 import java.util.function.Supplier;
  12 
  13 public class ExpressionSwitch {
  14     public static void main(String... args) {
  15         new ExpressionSwitch().run();
  16     }
  17 
  18     private void run() {
  19         check(T.A, "A");
  20         check(T.B, "B");
  21         check(T.C, "other");
  22         assertEquals(exhaustive1(T.C), "C");
  23         assertEquals(scopesIsolated(T.B), "B");
  24         assertEquals(lambdas1(T.B).get(), "B");
  25         assertEquals(lambdas2(T.B).get(), "B");
  26         assertEquals(convert1("A"), 0);
  27         assertEquals(convert1("B"), 0);


   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986 8222169 8224031
   4  * @summary Check expression switch works.
   5  * @compile/fail/ref=ExpressionSwitch-old.out -source 9 -Xlint:-options -XDrawDiagnostics ExpressionSwitch.java
   6  * @compile ExpressionSwitch.java
   7  * @run main ExpressionSwitch
   8  */
   9 
  10 import java.util.Objects;
  11 import java.util.function.Supplier;
  12 
  13 public class ExpressionSwitch {
  14     public static void main(String... args) {
  15         new ExpressionSwitch().run();
  16     }
  17 
  18     private void run() {
  19         check(T.A, "A");
  20         check(T.B, "B");
  21         check(T.C, "other");
  22         assertEquals(exhaustive1(T.C), "C");
  23         assertEquals(scopesIsolated(T.B), "B");
  24         assertEquals(lambdas1(T.B).get(), "B");
  25         assertEquals(lambdas2(T.B).get(), "B");
  26         assertEquals(convert1("A"), 0);
  27         assertEquals(convert1("B"), 0);


< prev index next >