Why do I need to explicitly cast char primitives on byte and short?

前端 未结 2 1344
心在旅途
心在旅途 2020-12-12 01:51

Concerning primitives: When I cast from smaller to bigger types, the casts are implicit, when I cast from bigger to smaller types, I need to explicitly cast the primitives,

2条回答
  •  时光取名叫无心
    2020-12-12 02:25

    I've taken this from the language specification:

    "First, the byte is converted to an int via widening primitive conversion (§5.1.2), and then the resulting int is converted to a char by narrowing primitive conversion (§5.1.3)."

提交回复
热议问题