byte a1 = 2, a2 = 4, a3; short s = 16; a2 = s; a3 = a1 * a2;
a3 = (byte)a1 * a2;
JVM 操作码一共256个,其中乘法的只有imul,lmul,fmul,dmul,byte和short会转为int用imul指令,计算结果也是int。int隐式转byte错误。当然像go这样更把简洁奉为自己的行为哲学的语言是不支持隐式转换的。
参考The Java® Virtual Machine Specification Java SE 8 Edition: