This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?