The good and the bad static pattern ?
Remi Forax
forax at univ-mlv.fr
Mon Jan 18 14:31:55 UTC 2021
> De: "Tagir Valeev" <amaembo at gmail.com>
> À: "Amber Expert Group Observers" <amber-spec-observers at openjdk.java.net>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Lundi 18 Janvier 2021 09:17:30
> Objet: Re: The good and the bad static pattern ?
> I think it should be essential to be able to declare a pattern outside of the
> type it matches. We cannot declare all possible string patterns inside the
> java.lang.String. People would like to declare their own string patterns.
> With best regards,
We may still be able to access pattern outside the type it match without supporting it as a static pattern.
I'm thinking about a way that make the type explicitly.
Same example with a tentative syntax (there may be a better one)
switch(o) {
case String.matcher("(a*)(b*)", var matcher) -> ...
case String text && Integer.parseInt(text, var value) -> ...
}
cheers,
> Tagir Valeev
Rémi
> On Mon, Jan 18, 2021 at 3:03 PM Remi Forax < [ mailto:forax at univ-mlv.fr |
> forax at univ-mlv.fr ] > wrote:
>> In the last document sent by Brian, there is a notion of static Pattern.
>> Here is an example of static patterns
>> switch(o) {
>> case String.matcher("(a*)(b*)", matcher -> ...
>> case Integer.parseInt(var value) -> ...
>> }
>> The first pattern, check if o is an instance of a String that match the regex
>> "(a)(b)" and provides the Matcher to retrieve the matching groups.
>> The second pattern, check if o is an instance of a String and can be parsed as
>> an integer and bind that integer to value.
>> The first pattern correspond to an instance method inside java.lang.String,
>> while the second pattern correspond to a static method inside
>> java.lang.Integer.
>> One problem is that while it's obvious that the first pattern starts by checking
>> if o is an instanceof String,
>> it's far less clear from a user POV that the second pattern does exactly the
>> same thing and does not check if o is an instance of Integer.
>> So should we support the form of the second pattern, a static Pattern linked to
>> a static method ?
>> Or should we restrict ourselves to static patterns that are expressed as
>> instance method ?
>> regards,
>> Rémi
More information about the amber-spec-observers
mailing list