1 /**
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986
   4  * @compile/fail/ref=MultipleLabelsStatement-old.out -source 9 -Xlint:-options -XDrawDiagnostics MultipleLabelsStatement.java
   5  * @compile --enable-preview -source 12 MultipleLabelsStatement.java
   6  * @run main/othervm --enable-preview MultipleLabelsStatement
   7  */
   8 
   9 import java.util.Objects;
  10 import java.util.function.Function;
  11 
  12 public class MultipleLabelsStatement {
  13     public static void main(String... args) {
  14         new MultipleLabelsStatement().run();
  15     }
  16 
  17     private void run() {
  18         runTest(this::statement1);
  19     }
  20 
  21     private void runTest(Function<T, String> print) {
  22         check(T.A,  print, "A");
  23         check(T.B,  print, "B-C");
  24         check(T.C,  print, "B-C");
  25         check(T.D,  print, "D");
  26         check(T.E,  print, "other");
  27     }
  28 
  29     private String statement1(T t) {
  30         String res;
  31 
  32         switch (t) {
  33             case A: res = "A"; break;
  34             case B, C: res = "B-C"; break;
  35             case D: res = "D"; break;
  36             default: res = "other"; break;
  37         }
  38 
  39         return res;
  40     }
  41 
  42     private void check(T t, Function<T, String> print, String expected) {
  43         String result = print.apply(t);
  44         if (!Objects.equals(result, expected)) {
  45             throw new AssertionError("Unexpected result: " + result);
  46         }
  47     }
  48 
  49     enum T {
  50         A, B, C, D, E;
  51     }
  52 }