我知道这个问题多次讨论过,但我还是不明白.
研究这段代码:
public class Main {
public static void var(Integer x, int y) {
System.out.println("Integer int");
}
public static void var(int... x) {
System.out.println("int... x");
}
public static void var(Integer... x) {
System.out.println("Integer...");
}
public static void main(String... args) {
byte i = 0;
Integer i2 = 127;
var(i, i2);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的大脑遵循规则:
加宽
拳击
拳+可变参数
根据这条规则,我会做下一步行动
1.byte扩展到int
现在我有int Integer ,并且存在方法需要Integer和int
2.make拳击
因此.int- > Integer和Integer- > int参数
我认为这些论点是适用的,并且有望看到
Integer int …Run Code Online (Sandbox Code Playgroud) 我有两个编译器编译得很好,但我希望Java抱怨模糊的可能性.
public Foo(int id, Bar bar, String name, String description){
}
public Foo(int id, Bar bar, String... values){
}
Run Code Online (Sandbox Code Playgroud)
是什么赋予了?