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

Compilation error thrown when long literal used with yield

XMLWordPrintable

    • b15
    • Verified

      The below code is using long literal with yield and it should compile successfully. However, it reports compilation error.

      class Test {
          public void check() {
              var num = switch (1) {
                  case 1:
                      yield 0L; //Works with yield 0.0f, 0.0d and (long)0L
                  default:
                      yield 0;
              } ;
          }
      }

      Result:

      Test.java:5: error: not a statement
                                              case 1 : yield 0L;
                                                       ^
      Test.java:5: error: ';' expected
                                              case 1 : yield 0L;

            jlahoda Jan Lahoda
            rchandra Ravi Chandra
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: