<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="">
The feature you are talking about is “constant patterns”, which is on the list.  It involves using literals (strings, numbers) as patterns.  <br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On May 29, 2024, at 10:49 AM, Georgi Stoyanov <<a href="mailto:gstoyanov@live.com" class="">gstoyanov@live.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="elementToProof" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
Hi, thank you for the quick response!</div>
<div class="elementToProof" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
<br class="">
</div>
<div class="elementToProof" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
Yes, regarding the lists, it's indeed weak. But regarding actually the objects and matching them directly based on their values, without need to write something like case Person(name, age) where name == "Alice" && age == 40, but just case Person("Alice", 40)
 is really good feature, isn't it?</div>
<div class="elementToProof" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
<br class="">
</div>
<div class="elementToProof" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
<br class="">
</div>
<div id="Signature" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;" class="">
Kind Regards,<span class="Apple-converted-space"> </span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;" class="">
Georgi Stoyanov</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;" class="">
<br class="">
</div>
</div>
<div id="appendonsend" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
</div>
<hr tabindex="-1" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline-block; width: 839.859375px;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""></span>
<div id="divRplyFwdMsg" dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<font face="Calibri, sans-serif" style="font-size: 11pt;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>Brian Goetz <<a href="mailto:brian.goetz@oracle.com" class="">brian.goetz@oracle.com</a>><br class="">
<b class="">Sent:</b><span class="Apple-converted-space"> </span>Wednesday, May 29, 2024 4:21 PM<br class="">
<b class="">To:</b><span class="Apple-converted-space"> </span>Olexandr Rotan <<a href="mailto:rotanolexandr842@gmail.com" class="">rotanolexandr842@gmail.com</a>><br class="">
<b class="">Cc:</b><span class="Apple-converted-space"> </span>Georgi Stoyanov <<a href="mailto:gstoyanov@live.com" class="">gstoyanov@live.com</a>>;
<a href="mailto:amber-dev@openjdk.org" class="">amber-dev@openjdk.org</a> <<a href="mailto:amber-dev@openjdk.org" class="">amber-dev@openjdk.org</a>><br class="">
<b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: Pattern matching improvements</font>
<div class=""> </div>
</div>
<div class="" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; line-break: after-white-space;">
Yes, these sorts of arguments are why I describe it as a weak candidate.  One only needs to think about it for a minute or so to come up with a whole pile of “follow on features” (“can I have a wildcard indicator that means any number of intervening elements”,
 “can I have a way to express an element matching P comes before an element matching Q”, etc).  
<div class=""><br class="">
</div>
<div class="">List patterns are fundamental in languages where cons-lists (such as Lisp or Haskell) are a foundational data structure in the langauge.  In that case, matching head/tail becomes a fundamental feature.  But that’s not Java.  <br class="">
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On May 29, 2024, at 9:12 AM, Olexandr Rotan <<a href="mailto:rotanolexandr842@gmail.com" class="">rotanolexandr842@gmail.com</a>> wrote:</div>
<br class="x_Apple-interchange-newline">
<div class="">
<div dir="auto" class="">I would like to say that, imo, point that list (or any sequential collection/array) patterns make code readable is a really brave assumption to say the least. I had some experience reading code like this in C#, and to say that I was
 not impressed would be an understatement. For me, it gives off strong regex vibes, which are, meanwhile really powerful tool, known to be barely readable.
<div dir="auto" class="">Also example you have provided above seems kind of python-like in a way that in which situation would you expect List OR single object as input. Unless there are union types (which I'm also not a fan of to be fair), your example is
 not from the java world, in my opinion.</div>
<div dir="auto" class="">The more realistic applixation for such patterns is match "shape" of collection, if you already know you are dealing with collection, but I'm not sure that game worth the candle to be fair. I guess such patterns could be more effective
 then traditional ways to do things that they are intended to substitute, so maybe in some caseslike data-oriented programming performance improvements could be significant, but besides I would think ten times before introducing another regex into the language.</div>
</div>
<br class="">
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Wed, May 29, 2024, 16:02 Brian Goetz <<a href="mailto:brian.goetz@oracle.com" class="">brian.goetz@oracle.com</a>> wrote:<br class="">
</div>
<blockquote class="x_gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">
<div class="" style="word-wrap: break-word; line-break: after-white-space;">We take inspiration from many sources, including many existing languages that have pattern matching.  
<div class=""><br class="">
</div>
<div class="">I think what you’re asking is: “have you considered List patterns”.  And indeed, we have.  List patterns are the dual to list literals (more generally, collection patterns are the dual to collection literals); we would consider introducing collection
 patterns when we are able to treat them holistically with collection literals.  However, of all the pattern matching features one could craft “have you considered X” for, list patterns are among the weakest, and so these are likely to be lower priority than
 other pattern matching features in the pipeline (e.g., varargs patterns, constant patterns, etc.). </div>
<div class="">
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On May 29, 2024, at 7:58 AM, Georgi Stoyanov <<a href="mailto:gstoyanov@live.com" target="_blank" rel="noreferrer" class="">gstoyanov@live.com</a>> wrote:</div>
<br class="">
<div class="">
<div class="" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
Hey folks,</div>
<div class="" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; text-align: left; margin-top: 1em; margin-bottom: 1em; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
I'm really excited about the new Java features that keep getting added, and I had an idea I wanted to share. Have you thought about introducing a pattern matching feature similar to Scala’s, which allows for more concise and readable code?</div>
<div class="" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; text-align: left; margin-top: 1em; margin-bottom: 1em; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
In Scala, you can match a list that starts with a specific element without having to spell everything out. For example:</div>
<div class="" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
case List(_, 2, _*) => "I only care that this list has 2 as the second element"<br class="">
case Person("Alice", age) => "It's Alice"<br class="">
<br class="">
This approach makes the code less verbose and lets you focus directly on the elements you care about. It’s a lot cleaner than extracting elements and comparing them separately, which is what we do now in Java.</div>
<div class="" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; text-align: left; margin-top: 1em; margin-bottom: 1em; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
I think adding something like this to Java would be a big win, making pattern matching more powerful and the code more readable.</div>
<div class="" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; text-align: left; margin-top: 1em; margin-bottom: 1em; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
Just wanted to throw this idea out there and see what you all think.</div>
<div class="" style="font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; text-align: left; margin-top: 1em; margin-bottom: 1em; font-family: Calibri, Helvetica, sans-serif; font-size: 11pt;">
<br class="">
Kind Regards,<span class=""> </span><br class="">
Georgi Stoyanov</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</body>
</html>