<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<font size="4"><font face="monospace">I am pretty sure I saw some
spec language for this go by, but Gavin can fill in the
details. But yes, this is desirable because it should be
possible to mix enums and records under a sealed type:<br>
<br>
sealed interface X { }<br>
enum E implements X { A; }<br>
record R(int x) implements X { }<br>
<br>
...<br>
<br>
switch (x) { <br>
case E.A: ...<br>
case R(int x): ...<br>
// exhaustive!<br>
}<br>
<br>
There is some spec trickiness because switches on enum selectors
_must_ use unqualified names historically, and this has to be
rationalized.<br>
</font></font><br>
<div class="moz-cite-prefix">On 9/26/2023 8:32 AM, Tagir Valeev
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAE+3fjYcnmTi-050SczFs4vP_S2_mRMJhXKx0HpFz2aQX+A9rQ@mail.gmail.com">
<pre class="moz-quote-pre" wrap="">Hello! As we are finalizing this feature, can we squeeze in a little
improvement? Namely, support enum and patterns within the same case
label, provided that the patterns do not declare any variables. Like:
enum X {A, B}
static void test(Object obj) {
switch (obj) {
case String _, X.B -> System.out.println("B or String");
default -> System.out.println("other");
}
}
public static void main(String[] args) {
Test.test("ddd");
Test.test(X.B);
}
Currently, such a code is not supported. Or will it be considered in
future JEPs?
With best regards,
Tagir Valeev.
On Mon, Sep 25, 2023 at 6:25 PM Mark Reinhold <a class="moz-txt-link-rfc2396E" href="mailto:mark.reinhold@oracle.com"><mark.reinhold@oracle.com></a> wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">
<a class="moz-txt-link-freetext" href="https://openjdk.org/jeps/456">https://openjdk.org/jeps/456</a>
Summary: Enhance the Java language with unnamed variables, which
can be initialized but not used, and unnamed patterns, which match a
record component without stating the component's name or type. Both are
denoted by an underscore character, _.
- Mark
</pre>
</blockquote>
</blockquote>
<br>
</body>
</html>