<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Reconstruction expressions are built on matching pairs of constructors and deconstruction patterns.  We can put deconstruction patterns in interfaces (Map.Entry is a prime example), but not constructors.  At some point we may bring the notion of factory into
 the language more formally, in which case we could pair deconstruction patterns with either constructors or factories, and interfaces can have factories, so we might be able to get to something like what you’re asking about in the future, but currently that’s
 quite a few steps down the road.
<div class=""><br class="">
</div>
<div class="">Without some code in the interface for “how do I make a new one”, reconstruction expressions don’t really make sense.  It would not be reasonable to, say, look at the dynamic type of the receiver and try to guess how to make a new one based on
 that; a reconstruction expression should be given clear semantics based on the static types involved.  So for the time being, your example would be over the horizon of what reconstruction expressions could do — because it’s not even obvious what they _should_
 do in this situation.  </div>
<div class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Nov 22, 2023, at 7:28 AM, Sebastian Fischer <<a href="mailto:mail@sebfisch.de" class="">mail@sebfisch.de</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div class="">Hello.</div>
<div class=""><br class="">
</div>
<div class="">Regarding the new features for pattern matching in JDK 21 I have some interesting use cases that highlight how they enable new ways to structure programs:</div>
<div class=""><br class="">
</div>
<div class=""><a href="https://github.com/sebfisch/java21-demo/wiki/Pattern-Matching" class="">https://github.com/sebfisch/java21-demo/wiki/Pattern-Matching</a></div>
<div class=""><br class="">
</div>
<div class="">Is this the right place to discuss them?</div>
<div class=""><br class="">
</div>
<div class="">The first example uses a file search program to illustrate how algebraic data types are useful in stream pipelines, especially in handling errors as values when using a functional programming style. The second example uses tree-structured data
 and shows how core ideas from functional programming, especially related to data traversal, can be integrated into Java, leveraging streams and other functional programming patterns. Interestingly, the operations for data traversal can be reused instead of
 implementing specialized variants for each new tree structure.<br class="">
</div>
<div class=""><br class="">
</div>
<div class="">I would be interested in what you expect about how the examples might change with future developments of Project Amber, especially regarding reconstruction expressions [1] and their relation to interfaces.</div>
<div class=""><br class="">
</div>
<div class="">For example, the interface</div>
<div class=""><br class="">
</div>
<div class="">    interface Named { String name(); }</div>
<div class=""><br class="">
</div>
<div class="">can be implemented automatically by a record</div>
<div class=""><br class="">
</div>
<div class="">    record Person(String name) implements Named {}</div>
<div class=""><br class="">
</div>
<div class="">because the record component matches the signature of the interface.</div>
<div class=""><br class="">
</div>
<div class="">It would be useful to be able to write<br class="">
</div>
<div class=""><br class="">
</div>
<div class="">    named with { name = "New Name" }</div>
<div class=""><br class="">
</div>
<div class="">for all implementations of `Named` (not only `Person`) and I wonder how `Named` could in the future be adjusted accordingly such that records still implement it automatically.</div>
<div class=""><br class="">
</div>
<div class="">Best,</div>
<div class="">Sebastian<br class="">
</div>
<div class=""><br class="">
</div>
<div class="">[1] <a href="https://mail.openjdk.org/pipermail/amber-spec-experts/2022-June/003461.html" class="">
https://mail.openjdk.org/pipermail/amber-spec-experts/2022-June/003461.html</a></div>
<div class=""><br class="">
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>