I learnt that i+=2
is the short-hand of i=i+2
. But now am doubting it.
For the following code, the above knowledge holds no good:
byte b=0;
b=b+2; //Error:Required byte, Found int
The above code is justifiable, as 2
is int
type and the expression returns int
value.
But, the following code runs fine:
byte b=0; b+=2; //b stores 2 after += operation
This is forcing me to doubt that the +=
short-hand operator is somewhat more than I know.
Please enlighten me.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…