<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<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 type="cite" 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. <br>
</body>
</html>