1.short s = 1; s = s + 1; Is there a problem? What if it's solved?
Short S = 1; s + = 1; Is there a problem? What if it's solved?
2. Understanding:
Short S=1;
s=s+1;
Nature is the compiler does not pass the hint loss accuracy
So:
Short S=1;
S+=1;
Why can it be compiled through that?
There is one more question:
Implicit type conversions can be auto-byte->short->int->long from small to large, that is, if you lose precision in turn, you must perform a display type conversion
And S+=1 's meaning is different from s = s+1, s=s+1 This sentence first executes s+1 and assigns the result to S, since 1 is the int type, so the return value of the s+1 is int, and the compiler automatically performs an implicit type conversion
So assigning an int type to short will make an error, and s+=1 is different because it is the + = operator, and at parse time S+=1 is equivalent to S = (short) (s+1), which doubles as
S+=1 <=> s = (type of s) (s+1)
Java basic knowledge hardening 01:short s = 1; s = s + 1; with short s = 1; s + = 1;