I prefer default to be special and has to be at the end thus starts warning 
about default not being at the end.
I think case null should be special too, for the same reason, case null 
dominates every cases while default dominates none. 

Rémi

----- Mail original -----
> De: "Brian Goetz" <[email protected]>
> À: "Tagir Valeev" <[email protected]>, "amber-spec-experts" 
> <[email protected]>
> Envoyé: Vendredi 3 Novembre 2017 22:25:18
> Objet: Re: default branch placement in switch

> Yeah, this has to change.  In existing switches, there are no case
> labels other than default, so order is irrelevant.  But now that
> patterns have overlapping match-sets, default should be considered to
> dominate other cases, so it should go last.
> 
> Compatibility-wise, we have two choices for how to get there; carve out
> a permanent exception for switches where all cases are type-restating
> constant patterns, 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.
> 
> 
> 
> On 11/3/2017 5:10 PM, Tagir Valeev wrote:
>> Hello!
>>
>> Currently the default branch can be placed in any place inside the
>> switch operator, e.g. like this:
>>
>> switch(i) {
>> case 1: System.out.println("one");break;
>> default: System.out.println("other");break;
>> case 2: System.out.println("two");break;
>> }
>>
>> In this case behavior does not change on the order of case blocks.
>> However in pattern matching the order of cases usually matters: if
>> some pattern matches, this means that the subsequent patterns will not
>> be checked. Does this mean that with pattern matching the default
>> branch makes all the subsequent case blocks unreachable? Or default
>> can still be located anywhere and is checked only after any other
>> pattern?
>>
>> With best regards,
> > Tagir Valeev

Reply via email to