促销的规则是"当操作数具有不同类型时,自动二进制数字促销发生,较小的操作数类型转换为较大的".但操作数是相同类型的,例如,
byte=byte+byte // Compile time error... found int..
Run Code Online (Sandbox Code Playgroud)
那为什么会这样呢?
Java 运算符是否返回 int 类型?
short a = 1;
short b = 2;
short c = a&b;
short d = a+b;
long e = a&b;
Run Code Online (Sandbox Code Playgroud)
如果是 'c', 'd' 他们有类型不匹配错误。为什么?和 'e' 没有错误的情况。为什么??
java ×2