4 java
public class Yikes1 {
public static void go(Long n) {
System.out.println("Long "); // printed
}
public static void go(Short n) {
System.out.println("Short "); // don't know why isn't this printed
}
public static void go(int n) {
System.out.println("int "); // printed
}
public static void main(String [] args) {
short y = 6;
long z = 7;
go(y);
go(z);
}
}
Run Code Online (Sandbox Code Playgroud)
在打印输出之前,短值是如何转换为int的?
我认为只有当dataype-short不可用时才能扩展工作,所以它会查找下一个可用的数据类型,在这种情况下是int,但是这里定义了短数据类型,那么为什么自动推广会发生?
绑定序列的工作原理如下:
int--> int)int --> long)int --> Integer)int --> int...)