case null vs null pattern
Remi Forax
forax at univ-mlv.fr
Sat Apr 16 12:57:34 UTC 2022
Hi all,
i maybe wrong but it seems that the spec consider null as a kind of case instead of as a kind of pattern, which disables the refactoring that should be possible with the introduction of the record pattern.
Let suppose i have a sealed type with only one implementation declared like this
sealed interface I {
record A() implements I { }
}
if null is part of the set of possible values, i have switches like this
switch(i) {
case null, A a -> // do something with 'a' here
}
Now we are introducing record pattern into the mix, so i can have a Box of I,
record Box(I i) { }
the problem is that i can not write
switch(box) {
case Box(A|null a) -> // do something with 'a' here
}
because null is handled as a kind of case instead of as a kind of a null pattern.
Should we introduce a null pattern instead of having a specific "case null" ?
(and disallow the null pattern in an instanceof ?)
regards,
Rémi
More information about the amber-spec-experts
mailing list