| Author |
Var-arg doubt
|
Ravi Yadav
Greenhorn
Joined: Mar 02, 2008
Posts: 29
|
|
Hi, I was experimenting with this piece of code: Why does this code throw a compiler error: ..... class Test{ void fun1(double... s){ System.out.println("inside A"); } void fun1(float...a){ System.out.println("inside S"); } public static void main(String arg[]){ new Test().fun1(5); } } ..... Test.java:11: reference to fun1 is ambiguous, both method fun1(double...) in Tes t and method fun1(float...) in Test match new Test().fun1(5); However this doesnt: class Test{ void fun1(double s){ System.out.println("inside A"); } void fun1(float a){ System.out.println("inside S"); } public static void main(String arg[]){ new Test().fun1(5); } } Thanks, Ravi
|
 |
Irina Goble
Ranch Hand
Joined: May 09, 2004
Posts: 75
|
|
|
The compiler cannot find the most specific method. Remember, it's trying to compare float[] and double[] and they are not comparable.
|
 |
 |
|
|
subject: Var-arg doubt
|
|
|