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

Invalid error for return in early construction context lambda

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • None
    • 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.

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

              Created:
              Updated:
              Resolved: