<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><div style="font-family: sans-serif;"><div class="markdown" style="white-space: normal;">
<p dir="auto">On 7 Jan 2021, at 6:18, Brian Goetz wrote:</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><p dir="auto">…Varargs patterns will build on it (as shown in the mail); if and when Java ever gets collection literals, there will be corresponding collection patterns too.  I think the path to streamlining this is not to try and simplify the syntax of the primitive, but move upwards to higher-level patterns.</p>
</blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">OTOH if patterns (like <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">switch ((O)x) case P v:</code> or <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">let P v = (O)x</code>) are the duals of assignment (like <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">x = v</code> or <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">O x = v</code>), then we are within our moral rights to make a pattern dualization of the venerable Java syntax <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">T[] x = {a,b,c}</code>, which is sugar for <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">T[] x = new T[]{a,b,c}</code>.  The sugar allows you to take the second <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">T[]</code> (and the <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">new</code>) for a typeful context (<code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">T[] x</code>).</p>
<p dir="auto">So without the sugar we get something like:</p>
<p dir="auto">T[] a = …;<br>
switch (a) { case new T[]{a,b,c}: }</p>
<p dir="auto">(The <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">new</code> from <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">new T[]{a,b,c}</code> is dropped because <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">new</code> doesn’t appear in patterns.)</p>
<p dir="auto">But with the same sugar, but dualized, we get:</p>
<p dir="auto">T[] a = …;<br>
switch (a) { case {a,b,c}: }</p>
<p dir="auto">In other words, when the pattern target is already an array, there is no need for the ceremony of repeating the array type, as with normal array declarations.</p>
<p dir="auto">Likewise:</p>
<p dir="auto">T[][] a2d = …;<br>
switch (a2d) { case {{a,b},{c,d}}: }</p>
<p dir="auto">I think this is what Tagir expected, and I think it is a reasonable “penciling out” of the basic moves of the game we are playing here.</p>
<p dir="auto">Moving on to varargs, the context of a method call marked varargs allows elision not only of the <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">new T[]</code> in <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">new T[]{a,b,c}</code> but also the braces, you you can equally say <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">f(a,b,c)</code> or <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">f(new T[]{a,b,c})</code>.</p>
<p dir="auto">(But not <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">f({a,b,c})</code>.  So, we don’t get <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">f2d({{a,b},{c,d}})</code> by analogy with nested array initializers.  Whatever.)</p>
<p dir="auto">If a pattern-method can take a pattern-flavored argument, and perhaps a varargs argument to boot, it’s pretty clear that additional moves could follow quickly:</p>
<p dir="auto">pattern f(pattern T[] a} { … }<br>
pattern f2d(pattern T[][] a) { … }<br>
pattern fv(pattern T a…) { … }<br>
// extra “pattern” keyword on parameters for emphasis…</p>
<p dir="auto">switch (x) {<br>
case f({a,b,c}): …   // omit <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">new T[]</code> b/c type<br>
case f2d({{d,e,f},{g}}): …   // omit <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">new T[][]</code> b/c type<br>
case fv(h,i,j,k): …   // omit <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">new T[]</code> and braces b/c varargs<br>
}</p>

</div></div></body>

</html>