Defined behavior on switch-case fall-through

Noctarius me at noctarius.com
Wed Feb 25 09:33:52 UTC 2015


Hey guys,

Sorry for crashing into the mailinglist but by looking at the Java
specification we're not really sure about it. I guess it might be
well defined but we want to make sure.

Looking at the following example we see a non natural ordered case
for fall-through. Looking at the spec there is an example which
defines the fall-through behavior, unfortunately the example uses a
natural ordered list of numbers.

switch(age){
case 0:
case 2:
case 4:
case 6: println("even");break;
case 1:
case 3:
case 5: println("uneven");break;
default: ....
}

In our example we do not have this behavior. We are sure the Java
compiler will compile it as it is above but Hotspot applies, as far
as I know, reordering on cases depending on the frequency of usage.
I expect it to only reorder fall-through blocks or let's call it
blocks without any order-dependency but is this how it works? Is
this case covered by the spec? Maybe it needs another example to
make it clear.

Thanks

Chris




More information about the core-libs-dev mailing list