上的 *** 作
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`
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)