When you encounter data transformations, it is always easy to ignore the conversion between the data and whether you can get the correct results. The summary is as follows: 1. Automatic promotion to large range in small scope
Different types of data are generally automatically promoted in small areas toward a wide range of directions. It can be understood that a large range of precision is larger than a small range, or the number of digits is more.
such as Byte b=3; B=b+2 will complain because 2 is of type int. Cannot force down to byte type.
and Byte b=3; int a=b+1; The result a=4 is obtained because the B is automatically promoted to the int type; 2. Large scale to small range casts
To revert back to the byte type, a cast is required.
such as Byte b=3; B= (byte) b+1; Of course, if the results overflow must be an error. 3. Automatic conversion (more interesting and characteristic, also relatively easy to overlook)
Mentioned earlier, short s=5; S=s+3 is a wrong type of report. And s+=3 will get the result s=8;
This is because the computer sees S+=3 as s= (the type of data on the left) s+3. And get the right results.
This example is usually assigned to the right.