Feedback on pattern matching (preview feature)
Remi Forax
forax at univ-mlv.fr
Sat Sep 25 19:39:42 UTC 2021
[re-sent to amber-spec-experts instead of amber-dev]
----- Original Message -----
> From: "Brian Goetz" <brian.goetz at oracle.com>
> To: "Vikram Bakshi" <vab2048 at gmail.com>, "amber-dev" <amber-dev at openjdk.java.net>
> Sent: Samedi 25 Septembre 2021 17:28:11
> Subject: Re: Feedback on pattern matching (preview feature)
> The example you cite is a peek into a feature not yet implemented (its a
> "and beyond" talk), so not only is there no "as patterns", but no
> patterns yet for which "as patterns" would be sensible.
>
> When we have deconstruction patterns as per the example, you'll be able
> to provide an optional binding:
>
> case Point(var x, var y): // don't care about the point
>
> case Point(var x, var y) p: // bind the point too
>
> which we believe will cover the need in a less "nailed on the side" way.
In that case (pun intended), we may want to make the binding of the type pattern optional too.
case Type: // type pattern with no binding
case Type variable: // type pattern + binding
This look like the dual of '_', instead of asking for a binding, make it optional.
If we follow that rabbit hole, then we should be able to write
case Point(var, var):
Rémi
>
> On 9/25/2021 10:21 AM, Vikram Bakshi wrote:
>> Hello,
>>
>> I was playing around with the new pattern matching and wondered about the
>> current absence of "as-patterns". Are there any plans to bring them to Java
>> in a future JEP?
>>
>> An example use case where they could be useful is demonstrated in the
>> recent video from the official Java YouTube channel (
>> https://youtu.be/UlFFKkq6fyU) at 17:22.
>>
>>
>> Regards,
> > Vikram
More information about the amber-spec-experts
mailing list