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.
$ 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.
- links to
-
Commit(master) openjdk/jdk/7a0cc796
-
Review(master) openjdk/jdk/22531