Why are there no byte or short literals in Java?

前端 未结 4 1771
盖世英雄少女心
盖世英雄少女心 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:29

    Another reason might be that the JVM doesn't know about short and byte. All calculations and storing is done with ints, longs, floats and doubles inside the JVM.

提交回复
热议问题