First, the range of values for these data classes is clarified:
BYTE: -128~127
Short: -2^15~2^15-1
char:0~65536
int: -2^31~2^31-1
Take a look at the following code:
byte B = 100;
Short S = b; Correct, because the value range of byte is within the short value range.
char C = b; Error because the value range of byte is not exactly within the value range of char.
c = S; Error because the value range of short is not exactly within the value range of char.
int x = b; Correct, because the value range of byte is within the value range of int.
x = S; Correct, because the value range of short is within the value range of int.
x = C; Correct, because the value range of char is within the value range of int.
This article is from the Java Technology Alliance blog, so be sure to keep this source http://simoniu.blog.51cto.com/2566344/1590164
Questions about the mutual assignment between Byte,short,char,int in Java