default branch placement in switch

Tagir Valeev amaembo at gmail.com
Fri Nov 3 21:10:52 UTC 2017


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


More information about the amber-spec-experts mailing list