Typecasting with shorthand operators
byte b=12;
b >>= 2; // Why is this legal? why does it auto开发者_StackOverflowmatically typecasts?
b = b >> 2; // Why is this illegal if the above is legal
b>>=2;
is same as
b = (byte) (b>> 2);
15.26.2 Compound Assignment Operators
A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.
精彩评论