But what was the reason that earlier they are not supporting this feature. Also we know that there are things like immutability and string pool. How this is going to affect the same things.
In earlier switch statement implementation, switch instructions are prepared using tableswitch or lookupswitch instructions. Both of these uses zero to three bytes offset padding and four bytes offset for case branches. In case of int, byte, short or character, case branch offset is in range whereas for long, float, double or string, it is out of range and hence give compilation error. The types used for switch are the one compatible with an efficient bytecode for control flow, and it may have been an important part for the reason of this choice.
But what was the reason that earlier they are not supporting this feature.
ReplyDeleteAlso we know that there are things like immutability and string pool. How this is going to affect the same things.
In earlier switch statement implementation, switch instructions are prepared using tableswitch or lookupswitch instructions. Both of these uses zero to three bytes offset padding and four bytes offset for case branches.
ReplyDeleteIn case of int, byte, short or character, case branch offset is in range whereas for long, float, double or string, it is out of range and hence give compilation error.
The types used for switch are the one compatible with an efficient bytecode for control flow, and it may have been an important part for the reason of this choice.