Just reviewing the rules for implementing the switch statement. Just for background, here are the rules as I understand them:
1. The switch statement argument must evaluate to an int primitive.
2. The case argument must evaluate to an int primitive AND it must be a compile-time constant. It is not enough to just be a final variable. It must be a compile-time constant (i.e. literal).
I was wondering what is the reasoning behind making such strict rules on the switch/case variables? Is it purely for compiler optimization or is there some other concept why it was limited to these boundaries. While I can understand the int primitive limitation for the switch operand, I think it takes away from the power of the switch statement and the ability to
test for a range of values by limiting it to compile-time constants.
Any thoughts?