为什么这会给出编译时错误?2在编译时是恒定的,因此这里应允许缩小,因为2在字节范围内.
public class Test {
public static void main(String[] args) {
ForTest test=new ForTest();
test.sum(1, 2); //compile time error here
}
}
class ForTest
{
public int sum(int a,byte b)
{
System.out.println("method byte");
return a+b;
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:ForTest类型中的方法sum(int,byte)不适用于arguements(int,int).
编辑:我认为答案就在这里:http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.3但我没有得到它:(