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 <&gt;? 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 `<&gt;` in&nbsp;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
> 
> 
> ------------------&nbsp;Original&nbsp;------------------
> From:                                                                                                                        "Brian Goetz"                                                                                    <brian.goetz at oracle.com&gt;;
> Date:&nbsp;Thu, Mar 24, 2022 03:02 AM
> To:&nbsp;"Tesla Zhang"<ice1000kotlin at foxmail.com&gt;;"amber-dev"<amber-dev at openjdk.java.net&gt;;
> 
> Subject:&nbsp;Re: Pattern matching for switch (Third Preview)
> 
> 
> 
> 
> 
> &gt; 0. I noticed a `<&amp;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.
> 
> &gt; 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".&nbsp; The key 
> part of this change is not the syntactic change from &amp;&amp; to `when`, but 
> moving the refinement from the pattern itself, to the switch.&nbsp; 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.&nbsp; 
> 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:
> 
> &nbsp;&nbsp;&nbsp;&nbsp; switch (aBoolean) {
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; case false &amp;&amp; false:&nbsp; // will never be selected!
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...
> &nbsp;&nbsp;&nbsp;&nbsp; }
> 
> 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.&nbsp; In the end, it felt like refinement 
> fit more cleanly in the conditional construct (switch) than in the 
> pattern machinery.&nbsp; This is why we do previews; to give decisions a 
> chance to settle.


More information about the amber-dev mailing list