Skip to content

Commit a315c0c

Browse files
committed
Auto saved by Logseq
1 parent 3678f0d commit a315c0c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

pages/P37 整数类型详解 2.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
- #Java #整数类型
2-
-
2+
- 当整数字面量没有超出byte的范围
3+
- 在Java中有这样一个规定,当整数型字面量没有超出byte的范围:可以直接赋值给byte类型的变量。
4+
- byte b = 127;// 这是允许的
5+
- 很显然,这是一种编译优化。同时也是为了方便程序员写代码。
6+
- 如果超出了范围,例如:
7+
- byte b = 128;// 编译报错
8+
- 这样就会报错,需要做强制类型转换,例如:
9+
- byte b = (byte) 128;
10+
- 在整数类型中,除了byte有这个待遇之外,short同样也是支持的。也就是说:如果整数型字面量没有超出short取值范围时,也是支持直接赋值的。

0 commit comments

Comments
 (0)