Comparing ranges with switch

Josiah Noel josiahnoel at gmail.com
Wed Mar 13 16:10:39 UTC 2024


we sorta have this with switch guards

switch (intyMcIntFace) {

case Integer i when i > 1 && i < 10 -> {}

case 42 -> {}


default -> throw new IllegalArgumentException("Unexpected value: ");

}

On Wed, Mar 13, 2024 at 8:16 AM Red IO <redio.development at gmail.com> 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/453171fc/attachment.htm>


More information about the amber-dev mailing list