int上的基本算术运算-Java

int上的基本算术运算-Java,第1张

int上的基本算术运算-Java

上的 *** 作

byte
char
并且
short
加宽
int
除非编译器可以确定该值的范围。

final byte a = 3, b = 4;byte c = a * b; // compilesfinal byte a = 3, b = 40;byte c = a * b; // compilesfinal int a = 3, b = 4;byte c = a * b; // compiles !!

byte a = 3, b = 4;byte c = a * b; // doesn't compile as the result of this will be `int` at runtime.final byte a = 30, b = 40;byte c = a * b; // doesn't compile as the value is too large, will be an `int`

BTW即使发生溢出也会编译。:]

final int a = 300000, b = 400000;int c = a * b; // compiles but overflows, is not made a `long`


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5461979.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存