Automatic type conversions Follow the following rules:
- If the data type of the participating operation is different, it is converted to the same type, and then the operation is performed.
- Conversions are performed in the direction of increased data length to ensure that the accuracy is not reduced. For example, int and long operations, the int is converted to long before the operation.
- All floating-point operations are performed in double-precision, even if the expression containing only float single-precision arithmetic is converted into double type and then calculated.
- Char and short participate in the operation, you must first convert to int type.
- In an assignment operation, the type of the right expression must be converted to the type of the left variable if the data type on either side of the assignment number is different. If the data type length of the right expression is longer than the left side, a portion of the data is lost, which reduces precision.
A rule that represents the automatic conversion of a type
"Java" Automatic type conversion rules