Overloading of matcher method Was: Deconstruction patterns

forax at univ-mlv.fr forax at univ-mlv.fr
Tue Mar 7 20:26:53 UTC 2023


> From: "Brian Goetz" <brian.goetz at oracle.com>
> To: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Sent: Tuesday, March 7, 2023 8:34:02 PM
> Subject: Re: Overloading of matcher method Was: Deconstruction patterns

> Remi pointed out privately that I didn't answer this question directly enough
> for his satisfaction.

> On 3/7/2023 9:20 AM, Brian Goetz wrote:

>> class Foo {
>> public Foo(String s) { ... }
>> public Foo(CharSequence seq) { ... }

>> public matcher Foo(String s) { ... }
>> public matcher Foo(CharSequence seq) { ... }
>> }

>> If i want to call Foo(CharSequence) with a String, i can use a cast, new
>> Foo((CharSequence) "foo") and the compiler selects the right overload.

>> How i can do the same to select the right matcher method inside a deconstructor
>> pattern ?
> For the constructor, you can guide (but not force) overload selection to the
> answer you want by providing more type information, which in turn will steer
> the "most specific" selection:

> new Foo((String) s)
> vs
> new Foo((CharSequence) s)

> For the deconstructor, we can do something similar with type patterns. We can
> say:

> case Foo(String s):
> vs
> case Foo(CharSequence s):

> For both of these use sites, both matchers are applicable; we're left with a
> question of which is "more specific" to the types present at the use site. As I
> have mentioned, the details are TBD, but we will draw inspiration from
> dualizing 15.12.2.5.
It's not exactly what i ask, the question is how to call the deconstructor that takes a CharSequence with a type pattern on a String. 
The inverse of 
String s = ... 
new Foo((CharSequence) s) 

should be 
case [Call the destructor Foo(CharSequence)] + Type Pattern (String) 

Rémi 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-experts/attachments/20230307/59731cf8/attachment-0001.htm>


More information about the amber-spec-experts mailing list