查看以下代码,请帮助
class ShortExample{
final int x=9;
int m=9;
short s=x; // works fine as it is a compile time constant
short ss=9; // also works as compiler handles it
// short sss=m; // doesn't work due to possible loss of precision
ShortExample.play(x); // why doesn't this work
ShortExample.play(9); // why doesn't this work
static void play(short s){
//do something
}
}
这里当我为短变量分配最终的int值时,它会编译而没有问题。但是如果我传递与参数相同的值,则会导致精度编译错误。它不应该工作,因为它是一个恒定的值吗?