<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Brian Goetz" <brian.goetz@oracle.com><br><b>To: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"amber-spec-experts" <amber-spec-experts@openjdk.java.net><br><b>Sent: </b>Tuesday, March 7, 2023 8:34:02 PM<br><b>Subject: </b>Re: Overloading of matcher method Was: Deconstruction patterns<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><font size="4"><font face="monospace">Remi pointed out privately
that I didn't answer this question directly enough for his
satisfaction. </font></font><br>
<br>
<div class="moz-cite-prefix">On 3/7/2023 9:20 AM, Brian Goetz wrote:<br>
</div>
<blockquote cite="mid:0a144b91-13ab-6af9-bce5-f5916c05bf73@oracle.com">class
Foo {
<br>
public Foo(String s) { ... }
<br>
public Foo(CharSequence seq) { ... }
<br>
<br>
public matcher Foo(String s) { ... }
<br>
public matcher Foo(CharSequence seq) { ... }
<br>
}
<br>
<br>
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.
<br>
<br>
How i can do the same to select the right matcher method inside a
deconstructor pattern ?
</blockquote>
<br>
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:<br>
<br>
new Foo((String) s)<br>
vs<br>
new Foo((CharSequence) s)<br>
<br>
For the deconstructor, we can do something similar with type
patterns. We can say:<br>
<br>
case Foo(String s):<br>
vs<br>
case Foo(CharSequence s):<br>
<br>
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. </blockquote><div><br></div><div>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.<br data-mce-bogus="1"></div><div>The inverse of<br data-mce-bogus="1"></div><div> String s = ...<br data-mce-bogus="1"></div><div> new Foo((CharSequence) s)<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>should be <br data-mce-bogus="1"></div><div> case [Call the destructor Foo(CharSequence)] + Type Pattern (String)<br data-mce-bogus="1"></div><div> <br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>RĂ©mi<br data-mce-bogus="1"></div><div><br></div></div></div></body></html>