[jdk17] RFR: 8270006: Switches with 'case null:' should be exhaustive
Rémi Forax
forax at openjdk.java.net
Wed Jul 7 12:40:51 UTC 2021
On Wed, 7 Jul 2021 11:45:11 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Code like:
>
> void exhaustiveAndNull(String s) {
> switch (s) {
> case null: break;
> }
> }
>
>
> should be rejected, because the switch is no exhaustive, but it is a "new" switch. (Note that this not a problem for switch expressions, which always have to be exhaustive.)
test/langtools/tools/javac/patterns/SwitchErrors.java line 192:
> 190: case null: break;
> 191: }
> 192: }
The other possible new syntax is "case default", but there is no error because it's exhaustive.
void exhaustiveCaseDefaultNoError(String s) {
switch (s) {
case default: break;
}
}
-------------
PR: https://git.openjdk.java.net/jdk17/pull/224
More information about the compiler-dev
mailing list