As we all know, Java implicitly automates type conversions when it comes to operations, so what happens when it's converted? Summarized as follows:
First, arithmetic operators
Monocular operator:+ (positive)-(minus) + + (self-increment 1)-(self-minus 1)
1.1 + (take positive)-(take negative)
When the operand is Byte,short,char, it is automatically converted to int, and the returned result is int.
When the operand is int,long, it does not convert, what is the original type, or what type.
1.2 + + (self-increment 1) --(self-minus 1)
No matter what type of operand it is, do not convert.
Binocular operator: +-*/% (take surplus)
1.3 +-*/% (take more)
When there is no long type in the two operands, the non-int type of the two operands is automatically converted to the int type, then participates in the operation, and returns the result as int;
When the two operands contain a long type, the non-long type of the two operands is automatically converted to a long type, and then the operation is taken, and the result is long;
two-bit operators
Bitwise operators:& (with), | (or), ^ (XOR), ~ (non), << (with symbol left), >> (with symbol right), >>> (unsigned Right shift)
2.1 & (with), | (or), ^ (XOR)
Same as the 1.3 case
2.2 ~ (non)
Same as the 1.1 case
2.3 << (with symbol left shift), >> (with symbol right shift), >>> (unsigned Right shift )
Same as the 1.1 case
Summarize
Although there are so many cases listed above, it is easy to remember.
That is: In addition to the self-increment self-reduction does not convert, all other cases are no long type, all non-int types are converted to int type; when there is a long type, it is converted to a long type
Description of automatic type conversion in Java for Byte,short,char,int,long operations