How to specify a constant is a byte or short?

前端 未结 3 1057
轮回少年
轮回少年 2021-01-11 13:01

For the long data type, I can suffix a number with L to make the compiler know it is long. How about byte and short?

As motivation, the following yields a type-mism

3条回答
  •  一向
    一向 (楼主)
    2021-01-11 13:54

    It's done automatically for you at the point of use

    If an int literal is assigned to a short or a byte and it's value is within legal range, the literal is assumed to be a short or a byte.

提交回复
热议问题