<div dir="ltr"><div>Hello.</div><div><br></div><div>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><br></div><div><a href="https://github.com/sebfisch/java21-demo/wiki/Pattern-Matching">https://github.com/sebfisch/java21-demo/wiki/Pattern-Matching</a></div><div><br></div><div>Is this the right place to discuss them?</div><div><br></div><div>
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></div><div><br></div><div>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><br></div><div>For example, the interface</div><div><br></div><div> interface Named { String name(); }</div><div><br></div><div>can be implemented automatically by a record</div><div><br></div><div> record Person(String name) implements Named {}</div><div><br></div><div>because the record component matches the signature of the interface.</div><div><br></div><div>It would be useful to be able to write<br></div><div><br></div><div> named with { name = "New Name" }</div><div><br></div><div>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><br></div><div>Best,</div><div>Sebastian<br></div><div><br></div><div>[1] <a href="https://mail.openjdk.org/pipermail/amber-spec-experts/2022-June/003461.html">https://mail.openjdk.org/pipermail/amber-spec-experts/2022-June/003461.html</a></div><div><br></div></div>