开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜