[英]why i am not getting reference to method is ambiguous in the following code?
我有 base 或 parent class 有 method1(int,int) 和 method1(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?
公共 class Test3{ 公共 static 無效 JavaHungry(異常 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 arguments 調用該方法。
對於 Java 編譯器,這並不含糊。
簡而言之,以下是您傳遞這些類型的值時將發生的調用。
method1(1, 1)
--> int, int
method1(1.0, 1)
--> double, double (編譯器自動將 1 轉換為 double)
method1(1.0, 1.0)
--> 雙倍,雙倍
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.