操作はint
に広がっています。
final byte a = 3, b = 4;
byte c = a * b; // compiles
final byte a = 3, b = 40;
byte c = a * b; // compiles
final 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`
ところでこれはオーバーフローにつながるにもかかわらず、コンパイルします。 :]
final int a = 300000, b = 400000;
int c = a * b; // compiles but overflows, is not made a `long`
良い質問。私は正直に答えを知らなかったが、これを見つけた。 http://mindprod.com/jgloss/multiplication.html – Zutty