Draft JEP on Primitive types in patterns, instanceof, and switch

forax at univ-mlv.fr forax at univ-mlv.fr
Thu Jan 26 21:19:09 UTC 2023


> From: "Kevin Bourrillion" <kevinb at google.com>
> To: "Per-Ake Minborg" <per-ake.minborg at oracle.com>
> Cc: "Remi Forax" <forax at univ-mlv.fr>, "Angelos Bimpoudis"
> <angelos.bimpoudis at oracle.com>, "amber-dev" <amber-dev at openjdk.org>
> Sent: Thursday, January 26, 2023 9:54:47 PM
> Subject: Re: Draft JEP on Primitive types in patterns, instanceof, and switch

> Depending on float equality is *dangerous*, but doesn't completely lack valid
> use cases.
> Doing so in this manner doesn't seem fundamentally different from all the other
> ways you can do it too; in my world, *any* of these ways will earn you a static
> analysis warning. The user can suppress that, and I think this is a wholly
> reasonable arrangement.

I agree apart on the idea of having to rely on a static analysis tool. I still remember the time before Java 1.5 where there was no warning. 
I would prefer a feature just released to not require a new static analysis. 

Anyway, that does not solve the issue raised by Guy, can case 0.0 and case -0.0 be both present in a same switch ? 

Rémi 

> On Thu, Jan 26, 2023 at 9:26 AM Per-Ake Minborg < [
> mailto:per-ake.minborg at oracle.com | per-ake.minborg at oracle.com ] > wrote:

>> Maybe certain values for float and double should be allowable (e.g. NaN
>> (matching all variants), POSITIVE_INFINITY, NEGATIVE_INFINITY and zero
>> (matching any zero value))? These are clearly defined. All other values would
>> render a compile-time error? (many question marks here) /P

>> From: amber-dev < [ mailto:amber-dev-retn at openjdk.org |
>> amber-dev-retn at openjdk.org ] > on behalf of Remi Forax < [
>> mailto:forax at univ-mlv.fr | forax at univ-mlv.fr ] >
>> Sent: Thursday, January 26, 2023 2:15 PM
>> To: Angelos Bimpoudis < [ mailto:angelos.bimpoudis at oracle.com |
>> angelos.bimpoudis at oracle.com ] >
>> Cc: amber-dev < [ mailto:amber-dev at openjdk.org | amber-dev at openjdk.org ] >
>> Subject: Re: Draft JEP on Primitive types in patterns, instanceof, and switch

>>> From: "Angelos Bimpoudis" < [ mailto:angelos.bimpoudis at oracle.com |
>>> angelos.bimpoudis at oracle.com ] >
>>> To: "amber-dev" < [ mailto:amber-dev at openjdk.org | amber-dev at openjdk.org ] >
>>> Sent: Thursday, January 26, 2023 10:48:47 AM
>>> Subject: Draft JEP on Primitive types in patterns, instanceof, and switch

>>> Hello all,

>>> I would like to share this draft JEP with you about primitive types in patterns,
>>> instanceof, and switch:

>>> [ https://openjdk.org/jeps/8288476 | https://openjdk.org/jeps/8288476 ]

>>> "Enhance pattern matching by allowing primitive types to appear anywhere in
>>> patterns. Extend instanceof to support primitive types, and extend switch to
>>> allow primitive constants as case labels."

>>> Comments very much welcomed!

>>> Many thanks,
>>> Angelos

>> I still think that the semantics proposed for pattern matching on primitive
>> types is useless complexity with the perverse side effect of normalizing the
>> usage of "default" in pattern matching (too many examples of this JEP are using
>> "default") but we already discussed that.

>> Allowing switching on double and float constants is just wrong.
>> Rust is actually trying to remove that feature
>> [ https://github.com/rust-lang/rust/issues/41255 |
>> https://github.com/rust-lang/rust/issues/41255 ]

>> I see no point to make the same mistake.

>> Otherwise, the rest is fine.

>> Rémi

> --
> Kevin Bourrillion | Java Librarian | Google, Inc. | [ mailto:kevinb at google.com |
> kevinb at google.com ]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230126/537d638d/attachment.htm>


More information about the amber-dev mailing list