Why does the first one doesnt give a compiler error?
Well, according to me in the first case the compiler is sure that the calue of i1 will never change and also since 20 is in the range of short, so it doesn't display an error But thats not the case in second case
I looked through the language specifications. I could not find anything under the sections "5.1.3 Narrowing Primitive Conversions" that talk about a narrowing down conversion from an int to a short. So I think you are probably correct. I am not sure though
There is an implicit narrowing conversion from a byte, short, char, or int to a byte, short, or char when the source is a constant expression that can be evaluated at compile time and the value fits in the target. This does not apply to arguments in method invocations.
See JLS 5.2 Assignment Conversion. [ January 07, 2005: Message edited by: Mike Gershman ]