我有一个基类或父类,其中有方法1(int,int)和方法1(double,double)重载。
public class Sub extends Base{
@overridden
method1(double,double) {`some manipulation`}
main{
method1(1,1); //i am not getting Compile Error(reference to method is ambiguous)!in java
}
}like so but what is the case here?
public class Test3{ public static void JavaHungry(Exception e) {}。
public static void JavaHungry(ArithmeticException e) {}
public static void JavaHungry(String s) {}
public static void main(String[] args) {
JavaHungry(null);`refernce to method is ambiguous`
}
}
在Java中。int
表示为 1
和 double
表示为 1.0
.
因此,当你调用 method1(1, 1)
它是在调用带有int参数的方法,对于Java编译器来说,这并不含糊。
对于Java编译器来说,这并不含糊。
简而言之,以下是当你传递这些类型的值时将发生的调用。
method1(1, 1)
--> int, int
method1(1.0, 1)
--> double, double (编译器自动将1转为双倍)
method1(1.0, 1.0)
-->;双,双