Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8294670

Enhanced switch statements have an implicit default which does not complete normally

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 20
    • 19
    • tools
    • None
    • b21

      From:
      https://mail.openjdk.org/pipermail/amber-dev/2022-September/007508.html

      This should compile:
      ---

      public class Example {
        sealed interface Action {
          record PrintAction() implements Action {}
          record DeleteAction() implements Action {}
        }


        public int foo(Action action) {
          switch (action) {
            case Action.PrintAction printAction -> {
              return 1;
            }
            case Action.DeleteAction deleteAction -> {
              return 2;
            }
          }
        }
      }
      ---

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: