Dishi Jain wrote:
is working fine for me. No compile time errors.
Because as per the description in Khalid Mughal, widening and then Boxing is taking place, while it is not legal.
To repeat...
Stephan van Hulst wrote:Like Henry said, there are some special rules for compile time constants which do not follow the general rules.
Thanks Stephan.
Anyway... interestingly, there are no byte or short compile time constants. Byte and short compile time constants are just int compile time constants.
Literals are compile time constants. A "10" is a int compile time constant. A "(short) 10" is actually not a short compile time constant, but is actually an int compile time constant that has been truncated to a short value (which is still 10 here). And... assigning this int compile time constant to an Integer reference just does boxing (and nothing else).
Henry