Questions about the record pattern
Reinier Zwitserloot
reinier at zwitserloot.com
Mon Jun 20 15:57:03 UTC 2022
On 20 Jun 2022 at 16:40:32, Hunor Szegi <hunor.szegi at gmail.com> wrote:
> ….
> The following pattern case label won’t work: "case Box(i, j) ->" , as "i"
> and "j" are not patterns.
>
Even money interprets this as 'i and j are valid, in-scope variables from
where the switch is being defined, and this is attempting to match the case
of a Box such that its deconstructed values are equal to i and j'. In other
words, Moving to Point instead:
var x = 5;
var y = 10;
switch (point) {
case Point(x, y) -> …
}
This could reasonably be interpreted as ‘match the case where x=5 and y =
10’, i.e. as if that said case Point(5, 10) -> ...
There’s some fairly severe limits on how far one should take ‘in a world
where nobody knows how to read these things, let’s enumerate the many many
ways folks might interpret some completely new language feature’, but java
does have rather a large amount of existing coders, so introducing new
features in a way that causes lots of confusion is best avoided, no doubt.
At any rate, one extra reason as to why omitting the var is stylistically
problematic.
I assume, given that the feature has been rolled out and is seeing active
additions, debates on syntax are valid :)
--Reinier Zwitserloot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20220620/d8ae0bfa/attachment.htm>
More information about the amber-dev
mailing list