Record constructor using Objects.requireNonNull
Christian Stein
sormuras at gmail.com
Thu Dec 31 18:22:33 UTC 2020
Hi,
Sascha's finding [1] applied to all requireNonNull variants of
java.util.Objects
import static java.util.Objects.*;
record Test(String v) {
Test {
requireNonNull(v);
requireNonNull(v, "v must be provided");
// requireNonNull(v, () -> "v must be provided");
requireNonNullElse(v, "w");
// requireNonNullElseGet(v, () -> "w");
}
}
leads to this error message after uncommenting one or both of the
supplier-taking lines:
Test.java:2: error: invalid compact constructor in record <init>
Test {
^
(compact constructor must not have return statements)
1 error
I ran javac from 16-ea+27 and 17-ea+3.
Shall I create an issue for this at https://bugs.openjdk.java.net or is
this an expected behaviour?
Cheers,
Christian
[1]: https://twitter.com/skohlmann/status/1344684426836500480
More information about the amber-dev
mailing list