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

后端 未结 15 3239
遥遥无期
遥遥无期 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:29

    I use bytes in lots of different places, mostly involving low-level data processing. Unfortunately, the designers of the Java language made bytes signed. I can't think of any situation in which having negative byte values has been useful. Having a 0-255 range would have been much more helpful.

    I don't think I've ever used shorts in any proper code. I also never use floats (if I need floating point values, I always use double).

    I agree with Tom. Ideally, in high-level languages we shouldn't be concerned with the underlying machine representations. We should be able to define our own ranges or use arbitrary precision numbers.

提交回复
热议问题