While going through rules for Case expressions in K&B book, its mentioned that only integer literal values and compile time constants are allowed.
I couldn't figure out why integer wrappers are not allowed in Case expressions. In the below example, variable i2 is final and it refers to Integer wrapper object (immutable). So compiler could easily use the value (200) instead of object.
Karthikeyan Kandasamy wrote:I couldn't figure out why integer wrappers are not allowed in Case expressions.
They could have been, but the language designers never bothered. You'd have to ask them for the real reason. My speculation, though - they never found a good reason to. Can you think of a situation where it would be genuinely useful?