Comparing ranges with switch
Brian Goetz
brian.goetz at oracle.com
Wed Mar 13 14:09:32 UTC 2024
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/299c4ef5/attachment.htm>
More information about the amber-dev
mailing list