开发者

Typecasting with shorthand operators

开发者 https://www.devze.com 2023-03-27 09:48 出处:网络
byte b=12; b >>= 2; // Why is this legal? why does it auto开发者_StackOverflowmatically typecasts?
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

精彩评论

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