Nullable switch
forax at univ-mlv.fr
forax at univ-mlv.fr
Thu Aug 6 21:35:43 UTC 2020
I've re-read the proposed spec about the nullable switch,
and it still don't understand why people will think that that the following switch is a nullable switch
switch(o) {
case String s ->
case Object o ->
}
The current spec merges the notion of totality and of nullability and i fail to understand why.
Moreover, the spec explain that we need a any pattern but don't explain why having an explicit syntax "any foo", which separate the notion of totality and nullability is not a good idea.
i wonder what is the problem of introducing a syntax "any foo" explicitly.
with the following rules for a nullable switch:
* A switch with a constant null case will accept nulls;
* If present, a constant null case must go first;
* A switch with an any case matches also accepts nulls;
* If present, an any case must go last.
By example,
Object o = ...
switch(o) {
case var o -> // non null Object
case any o -> // nullable Object
}
In that case, the following switch is not nullable
switch(o) {
case String s ->
case Object o ->
}
and the nullable version is
switch(o) {
case String s ->
case any o ->
}
regards,
Rémi
> De: "John Rose" <john.r.rose at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "Brian Goetz" <brian.goetz at oracle.com>, "amber-spec-experts"
> <amber-spec-experts at openjdk.java.net>
> Envoyé: Vendredi 24 Juillet 2020 03:20:20
> Objet: Re: Next up for patterns: type patterns in switch
> On Jul 23, 2020, at 2:53 PM, Remi Forax < [ mailto:forax at univ-mlv.fr |
> forax at univ-mlv.fr ] > wrote:
>> var x and default are not on the same plane. So it's not really a third thing.
>> We are introducing something special for the bottom, null, but not for the top ?
> Eh; null doesn’t need to be that special, but Brian’s point is that
> you can just mandate that it appears at the top or nowhere.
> If you don’t mandate that, then type-coverage checks ensure
> that a “case null” which appears after a nullable case (a total
> one) will be not-reachable, and a static error.
More information about the amber-spec-observers
mailing list