Why are there no byte or short literals in Java?

前端 未结 4 1766
盖世英雄少女心
盖世英雄少女心 2020-12-05 17:11

I can create a literal long by appending an L to the value; why can\'t I create a literal short or byte in some similar way? Why do I need to use an int literal with a cast?

4条回答
  •  情书的邮戳
    2020-12-05 17:45

    I suspect it's a case of "don't add anything to the language unless it really adds value" - and it was seen as adding sufficiently little value to not be worth it. As you've said, it's easy to get round, and frankly it's rarely necessary anyway (only for disambiguation).

    The same is true in C#, and I've never particularly missed it in either language. What I do miss in Java is an unsigned byte type :)

提交回复
热议问题