This essay is a review of the Java type conversion, convenient to forget the time of the query, but also want to help people with this need friends
First, data type classification:
Simple data types: integer, Real, character ((Byte-short-char)-int-long-float-double)
Second, simple type conversion
(1) Low-level to advanced conversion---automatic conversion: implicit conversion
byte i = 0;
int a =i;
Long B = i;
float c =b;
Double d =c;
Short J =i;
(2) advanced to low-level conversion---casts
int i=99;
byte b= (byte) i;
Char c= (char) i;
float f=i;
Double d = f;
f = (float) D;
(3) Packaging type transition
JAVA has a total of 6 wrapper classes: Boolean, Integer, Long, Float, Double, Character
Iii. Examples of conversions
Shorts = 1;
s= s +1;
And
Shorts = 1;
S+=1;
Is there a problem with the analysis?
Analysis: The first one will error, because s = S+1 will be implicitly converted to the int type, when an int type is assigned to the short type, it may be lost.
The second one is correct, because S+=1 has a cast, S = (short) (s+1), then no error is given.
JAVA type conversions: implicit conversions and casts