以下方法接受三个类型的参数,byte,int,int并且从另一个方法调用该方法,这会导致编译错误,该方法参数不适用于该方法int,int,int。默认情况下,在完成显式转换之前,字节参数是无法识别的。
public double subtractNumbers(byte arg1,int arg2,int arg3) {
double sum=arg1+arg2+arg3;
return sum;
}
现在方法调用另一个方法如下
public void call(){
subtractNumbers(15,16,17); /*Compile error,but 15 is in byte acceptable
range of -128 to 127 */
}
如果我更改上述调用,因为subtractNumbers((byte)15,16,17);它可以正常工作
当我声明一个变量byte c=15被接受但将15传递给字节参数时,为什么会出现编译错误;
int是byte,short,int,long的默认文字,那么为什么要接受字节c = 15而不转换而不是方法参数。
胡说叔叔
萧十郎
相关分类