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

Parse error with parenthesized pattern and guard using an array

XMLWordPrintable

    • b07

      This fails:

          public int test(Object o)
          {
              int[] arr = {1, 2};

              return switch (o) {
                  case (String s) when (arr[0] == 1) -> 0;
                  default -> 1;
              };
          }

      with

          ParenthesizedCombo.java:36: error: -> expected
                      case (String s) when (arr[0] == 1) -> 0;

      but not when e.g.,

          case (String s) when (s.isEmpty()) -> 0;

            abimpoudis Angelos Bimpoudis
            abimpoudis Angelos Bimpoudis
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: