Invalid error for return in early construction context lambda

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 24
    • Affects Version/s: None
    • Component/s: tools
    • None
    • b27
    • generic
    • generic

      This program should compile (with --enable-preview) but fails instead:

      $ cat C.java
      class C {
          C() {
              Runnable r = () -> {
                  return;
              };
              super();
          }
      }
      $ javac -d classes --enable-preview --release 23 C.java
      C.java:4: error: 'return' not allowed before explicit constructor invocation
                  return;
                  ^
      Note: C.java uses preview features of Java SE 23.
      Note: Recompile with -Xlint:preview for details.

            Assignee:
            Archie Cobbs
            Reporter:
            Archie Cobbs
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: