Weird java behavior with casts to primitive types

后端 未结 3 1869
不知归路
不知归路 2020-11-27 05:39

This was probably asked somewhere but I couldn\'t find it. Could someone clarify why this code compiles and prints out 1?

long i = (byte) + (cha         


        
3条回答
  •  天涯浪人
    2020-11-27 05:56

    Because both '+' and '-' are unary operators, and the casts are working on the operands of those unaries. The rest is math.

提交回复
热议问题