Last active
May 30, 2020 16:27
-
-
Save tonivade/297239e44da8192897cb7a7339f4b044 to your computer and use it in GitHub Desktop.
Java 14 bug in smart constructor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.Supplier; | |
public record Bug(int value) { | |
static void bug(Supplier<String> str) { | |
System.out.println(str.get()); | |
} | |
public Bug { | |
bug(() -> "hello"); | |
} | |
public static void main(String[] args) { | |
new Bug(1); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ java --enable-preview --source 14 Bug.java | |
Bug.java:9: error: invalid compact constructor in record Bug(int) | |
public Bug { | |
^ | |
(compact constructor must not have return statements) | |
Note: Bug.java uses preview language features. | |
Note: Recompile with -Xlint:preview for details. | |
1 error | |
error: compilation failed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ java --enable-preview --source 15 Bug.java | |
Bug.java:9: error: invalid compact constructor in record <init> | |
public Bug { | |
^ | |
(compact constructor must not have return statements) | |
Note: Bug.java uses preview language features. | |
Note: Recompile with -Xlint:preview for details. | |
1 error | |
error: compilation failed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment