如果有两个方法,如add(int,long)和add(long,int),这样的通话add(10,10)将被视为不确定性.
但是,如果我们有这样的例子,为什么它仍然被认为是歧义?
static void add(short num1, short num2) {
System.out.println("add(short, short)");
}
static void add(byte num1, long num2) {
System.out.println("add(byte, long)");
}
public static void main(String[] args) {
byte num1 = 10;
byte num2 = 10;
add(num1, num2);
}
Run Code Online (Sandbox Code Playgroud)
我想知道编译器如何确定它是模棱两可的?虽然(在我看来)它不应该因为add(short, short)需要两个类型的促销步骤,并add(byte, long)需要三个类型的促销..或者我有一个误解?