Comparing ranges with switch

David Alayachew davidalayachew at gmail.com
Wed Mar 13 15:40:11 UTC 2024


Hijacking for a second -- Where might one say we have overspent our ad-hoc
budget? Purely out of curiosity.

But very excited to hear that this might also extend to loops and whatnot.
That would simplify a lot of code out there.

On Wed, Mar 13, 2024 at 10:10 AM Brian Goetz <brian.goetz at oracle.com> wrote:

> As you observe, this is an entirely reasonable fit for switch.  However,
> if we were to just do labels like:
>
>     case 1..10:
>
> this would fall into the category of "ad-hoc syntax-oriented feature", and
> our budget for such things is limited (and arguably overspent.)  To make
> such a feature worthwhile, we'd want to address ranges more holistically,
> such as support in loops, arrays, ranges of other ordered types (such as
> long or enums), etc.  Which is a totally reasonable feature to consider,
> but is also more significant in scope.
>
>
>
> On 3/13/2024 8:16 AM, Red IO wrote:
>
> The switch statement saw a huge transformation over the past few releases.
> So I was quite surprised to realize that the current switch construct can't
> check the range of an value.
> Example case x is between y and z.
> I'm most likely not the first one to notice that. Is there any discussion
> about adding some sort of range pattern? Would fit in the notion of the
> switch checking patterns quite well.
>
> Great regards
> RedIODev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240313/0016a333/attachment-0001.htm>


More information about the amber-dev mailing list