<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Nov 3, 2017 at 5:25 PM, Brian Goetz <span dir="ltr"><<a href="mailto:brian.goetz@oracle.com" target="_blank">brian.goetz@oracle.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>or plan to eventually get to a place where default always comes last, even for "int" switches. If we want to get to the latter, we should start warning on this construct now.</blockquote><div><br></div><div>I favor starting to warn and eventually forbidding default in any position but last for all constructs that have it.</div><div><br></div><div>A switch with the default in the middle is extremely weird and confusing. If I'm reading code to understand what happens when i == 3, and I read as far as</div><div><br></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div>switch (i) {</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div> case 1:</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>  justOneStuff(); break();</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div> case 2:</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>  justTwoStuff(); break();</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div> default:</div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div>   </div><div>... then I immediately assume that this must be where execution is continuing. Worse, even if I do notice that there are more case labels to follow, and I resume searching for a `case 3:`, then when I don't find one I now risk making <i>another</i> error and forgetting to jump <i>back</i> to the default.</div><div><br></div><div>This is kind of insane. At first I was less worried because I thought "surely no one is actually doing this"... then I browsed our codebase.... yikes.</div><div><br></div><div>We should at least strongly consider this.</div><div><br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_2816769939487245128HOEnZb"><div class="m_2816769939487245128h5">
On 11/3/2017 5:10 PM, Tagir Valeev wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello!<br>
<br>
Currently the default branch can be placed in any place inside the<br>
switch operator, e.g. like this:<br>
<br>
switch(i) {<br>
case 1: System.out.println("one");brea<wbr>k;<br>
default: System.out.println("other");br<wbr>eak;<br>
case 2: System.out.println("two");brea<wbr>k;<br>
}<br>
<br>
In this case behavior does not change on the order of case blocks.<br>
However in pattern matching the order of cases usually matters: if<br>
some pattern matches, this means that the subsequent patterns will not<br>
be checked. Does this mean that with pattern matching the default<br>
branch makes all the subsequent case blocks unreachable? Or default<br>
can still be located anywhere and is checked only after any other<br>
pattern?<br>
<br>
With best regards,<br>
Tagir Valeev<br>
</blockquote>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_2816769939487245128gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div style="line-height:1.5em;padding-top:10px;margin-top:10px;color:rgb(85,85,85);font-family:sans-serif"><span style="border-width:2px 0px 0px;border-style:solid;border-color:rgb(213,15,37);padding-top:2px;margin-top:2px">Kevin Bourrillion |</span><span style="border-width:2px 0px 0px;border-style:solid;border-color:rgb(51,105,232);padding-top:2px;margin-top:2px"> Java Librarian |</span><span style="border-width:2px 0px 0px;border-style:solid;border-color:rgb(0,153,57);padding-top:2px;margin-top:2px"> Google, Inc. |</span><span style="border-width:2px 0px 0px;border-style:solid;border-color:rgb(238,178,17);padding-top:2px;margin-top:2px"> <a href="mailto:kevinb@google.com" target="_blank">kevinb@google.com</a></span></div></div></div></div></div></div></div>
</div></div>