【发布时间】:2014-05-30 07:19:27
【问题描述】:
根据我在 Java 方面的知识,如果源中的任何常量的字节范围超过以下范围,则在缩小类型转换时:
byte b=10; // allowed because 10 is in range of byte and 10 is a constant
但是当我输入这个时:
byte b=10l; // this is not allowed although 10 is in range of byte and is a constant
为什么会这样? 能否请您说出这些缩小转换在 Java 中发生的确切规则。
【问题讨论】:
-
AFAIK 这是一个"narrowing primitive conversion"(例如
byte b = 10)而不是“缩小类型转换”(例如(byte)10)。