public class ShortDivision {
public static void main(String[] args) {
short i = 2;
short j = 1;
short k = i/j;
}
}
编译这个代码会产生错误
ShortDivision.java:5: possible loss of precision
found : int
required: short
short k = i/j;
因为表达式i/j的类型明显为int,因此必须强制转换为short。