Why does bitwise AND of two short values result in an int value in Java?

后端 未结 5 1896
情话喂你
情话喂你 2020-12-07 02:10
short permissions = 0755;
short requested = 0700;
short result = permissions & requested; 

I get a compiler error:

error possib         


        
5条回答
  •  旧时难觅i
    2020-12-07 03:11

    I just wanted to add that you can actually avoid the cast if you use the arithmetic assignment operators. It's not faster or slower, just something that might be nice to know.

    short permissions = 0755;
    short requested = 0700;
    short result = permissions;
    result &= requested;
    

提交回复
热议问题