Automatic type conversion:
When the byte type is added to the int type, the byte type data is automatically promoted to int type data.
(Regular: Byte-to-byte conversions with a small footprint)
Attention! The conversion is valid only for constants, and variables do not convert!
For example:
Run error, Tip accuracy missing
Analysis: 3 is an int constant that can be automatically converted to byte, but B is a variable and cannot be automatically converted
For example, the following situation would overflow
String and any number with a + connection, representing the connection, to form a new string
To force type conversions:
- Char is a character data that converts integer data to the corresponding character according to an ASCII-encoded table, output a
- ' A ' is a character type data, so no conversion, output a
- ' A ' is the character data, 1 is the int type data, because the char data occupies 2 bytes, int occupies 4 bytes, the sum is the int type data, the output 98
- (char+1) is of type int, char (char+1) cast type is character data, output B
Java Novice Road--day 04 data type conversions