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);
}
}
在打印输出之前,短整型(short value)是如何转换为整型(int)的?
我原以为只有当数据类型 short 不可用时才会进行扩宽,然后寻找下一个可用的数据类型,而这里明确定义了 short 数据类型,那么自动提升是如何发生的呢?
short
和Short
不是同一件事。尝试使用一个接受short n
的方法来验证它。 - Jon Egeland