<div dir="ltr"><div dir="ltr">I assume this won't be an issue with the nullability JEP implemented (not sure where that is in the roadmap though)? That is, in this case we could expect things like this to work, right?<div><br></div><div>```</div><div>switch (p) {<br> case Pair!(Pair?(A a, B b), Pair?(C c, D d)): ...<br>}<br></div><div>```</div><div><br></div><div>or</div><div><br></div><div>```</div><div>switch (p) {<br> case Pair!(Pair!(A a, B b), Pair!(C c, D d)): ...<br>}<br></div><div>```</div><div><br></div><div>And if that is the case, then trying to be tricky now would be a waste anyway.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Brian Goetz <<a href="mailto:brian.goetz@oracle.com">brian.goetz@oracle.com</a>> ezt írta (időpont: 2023. szept. 26., K, 3:19):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<font size="4"><font face="monospace">The gap between exhaustiveness
and totality (which we call "remainder") is indeed somewhat
counterintuitive at first, because we would like for these two
words to mean the same thing. There were many, many discussions
regarding this in Record Patterns. This JEP extends the
surprise a little bit, but only in a quantitative, not
qualitative way; unboxing conversions are another place where we
encounter a gap between these two similar concepts.<br>
<br>
The first part of the example (Box<Box<String>>) is
not new to this JEP; this is how nested patterns work. (If you
think about it for long enough, you realize that the
alternatives are all nearly intolerable.) The
Box<Integer> example just adds one more form of remainder.<br>
<br>
Imagine it worked the way your intuition tells you it should
work. I'll start with the old case, nested record patterns.
Now, suppose you have:<br>
<br>
record Pair<T,U>(T t, U u) { }<br>
<br>
...<br>
<br>
Pair<Pair<A, B>, Pair<C, D>> p = ...<br>
<br>
switch (p) { <br>
case Pair(Pair(A a, B b), Pair(C c, D d)): ...<br>
}<br>
<br>
Under the David rules, this switch is not exhaustive, because it
matches neither Pair(null, _) or Pair(_, null). So what cases
would you have to add to the switch to satisfy the compiler's
complaints of non-exhaustiveness? Write the code, and then tell
me if you want to program in that language...<br></font></font><br>
</div>
</blockquote></div></div>