代码是
public class TestOverload {
public static void print(Float f, double d) {
System.out.println("Float,double");
}
public static void print(float f, double d) {
System.out.println("float,double");
}
public static void print(int f, double d) {
System.out.println("int,double");
}
// public static void print(int f, float d) {
// System.out.println("int,float");
// }
public static void print(double d1, double d) {
System.out.println("double,double");
}
public static void print(float d1, float d) {
System.out.println("float,float");
}
public static void main(String[] args) {
TestOverload.print(2, 3.0);
TestOverload.print(2, 3.0f);//Compiler error:The method print(float, double) is ambiguous for the type TestOverload
}
}
为什么它给出错误,而不是它应该选择 print(float d1, float d)
PS:在上面的代码中,如果我评论:
// public static void print(int f, double d) {
// System.out.println("int,double");
// }
然后调用 print(float d1, float d)...