class Dec26 {
public static void main(String[] args) {
short a1 = 6;
new Dec26().go(a1);
new Dec26().go(new Integer(7));
}
void go(Short x) { System.out.print("S "); }
void go(Long x) { System.out.print("L "); }
void go(int x) { System.out.print("i "); }
void go(Number n) { System.out.print("N "); }
}
输出:
i N
在上面的例子中,为什么编译器选择加宽选项(即 Integer --> Number)而不是拆箱 Integer 并选择 int 选项?
谢谢