Pattern matching for switch (Third Preview)
Tesla Zhang
ice1000kotlin at foxmail.com
Fri Mar 25 13:52:09 UTC 2022
Here:
"hello", as expected; but also case Integer i when i <> 0 dominates the label case 0. This leads to a simple, predictable, and readable ordering of case labels, where the constant
Regards,
Tesla
---Original---
From: "Gavin Bierman"<gavin.bierman at oracle.com>
Date: Fri, Mar 25, 2022 07:31 AM
To: "Tesla Zhang"<ice1000kotlin at foxmail.com>;
Subject: Re: Pattern matching for switch (Third Preview)
[Off-list]
Can you tell me precisely where you see the incorrect rendering of <>? I don’t see it at either URLs :-(
Which browser are you using, btw?
Thanks,
Gavin
> On 23 Mar 2022, at 19:14, Tesla Zhang <ice1000kotlin at foxmail.com> wrote:
>
> Hi Brian,
>
>
> Thanks for the quick reply! Two more small things:
>
>
> 0. I also see the `<>` in https://openjdk.java.net/jeps/8282272 as well :/
> 1. Is the 'allow null' thing aimed at adding `null` to all possible switches, so we cannot have empty switches (as `null` becomes an always-possible case candidate)?
>
>
> Best regards,
> Tesla
>
>
> ------------------ Original ------------------
> From: "Brian Goetz" <brian.goetz at oracle.com>;
> Date: Thu, Mar 24, 2022 03:02 AM
> To: "Tesla Zhang"<ice1000kotlin at foxmail.com>;"amber-dev"<amber-dev at openjdk.java.net>;
>
> Subject: Re: Pattern matching for switch (Third Preview)
>
>
>
>
>
> > 0. I noticed a `<&gt;` operator, is that a typo?
>
> Likely a rendering artifact; the markdown renderer in the bug system is
> different from that of the OpenJDK website, which ultimately is the
> definitive view.
>
> > 1. What's the motivation of replacing `??` with a new soft keyword? What's bad about `??`?
>
> This was discussed on the amber-spec-experts list in January; see
> threads rooted at "reviewing feedback on patterns in switch". The key
> part of this change is not the syntactic change from && to `when`, but
> moving the refinement from the pattern itself, to the switch. The
> change in syntax follows naturally from this change in location.
>
> FWIW, adjoining guards to patterns has some nasty surprises lurking,
> which we knew about but convinced ourselves we could ignore at first.
> For example, if we ever have switches over boolean (which we surely
> will, as pattern matching has been a forcing function for regularizing
> all aspects of switch, and this one will surely come), you can then get
> some bizarre combinations, which don't mean what you think they mean, like:
>
> switch (aBoolean) {
> case false && false: // will never be selected!
> ...
> }
>
> In the design discussion for this feature, we went back and forth
> several times between refining patterns and refining switch cases, since
> there were pros and cons of each. In the end, it felt like refinement
> fit more cleanly in the conditional construct (switch) than in the
> pattern machinery. This is why we do previews; to give decisions a
> chance to settle.
More information about the amber-dev
mailing list