This is similar to compiler specific behavior. When I embed code in Eclipse, starting Java 7, I do not see the compiler errors that you report for short to Integer or byte to Integer .
Instead, I see byte , short and int all can be assigned byte , short and Integer , but not Long , and Long can only be assigned Long . Interestingly, if you change the variables to primitives instead of wrapper types, the behavior of byte , short and int will not change, but now assignments from other types to Long are also performed.
javac 1.7.0_02 | byte | Byte || short | Short || int | Integer || long | Long | From byte | Yes | Yes || Yes | Yes || Yes | No || Yes | No | From short | Yes | Yes || Yes | Yes || Yes | No || Yes | No | From int | Yes | Yes || Yes | Yes || Yes | Yes || Yes | No | From long | No | No || No | No || No | No || Yes | Yes | Eclipse Indigo | byte | Byte || short | Short || int | Integer || long | Long | From byte | Yes | Yes || Yes | Yes || Yes | Yes || Yes | No | From short | Yes | Yes || Yes | Yes || Yes | Yes || Yes | No | From int | Yes | Yes || Yes | Yes || Yes | Yes || Yes | No | From long | No | No || No | No || No | No || Yes | Yes |
Given that different compilers allow different conversions, I suspect that the โcorrectโ behavior is not actually written in JLS. It seems that some conversions are done under the covers because the authors of the compiler considered this convenient (for example, byte a = (int)1 allowed, but byte a = (int)1000 not), and not because it is a documentary part of the language.
source share