Anyone using short and byte primitive types, in real apps?

后端 未结 15 3215
遥遥无期
遥遥无期 2021-02-20 08:09

I have been programming in Java since 2004, mostly enterprise and web applications. But I have never used short or byte, other than a toy program just to know

15条回答
  •  太阳男子
    2021-02-20 08:22

    The Java language itself makes it unreasonably difficult to use the byte or short types. Whenever you perform any operation on a byte or short value, Java promotes it to an int first, and the result of the operation is returned as an int. Also, they're signed, and there are no unsigned equivalents, which is another frequent source of frustration.

    So you end up using byte a lot because it's still the basic building block of all things cyber, but the short type might as well not exist.

提交回复
热议问题