aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Var-arg doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Var-arg doubt" Watch "Var-arg doubt" New topic
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Var-arg doubt
 
Similar Threads
Method Overloading
Overloading methods
Simple Query related with Inheritance
primitive widening doubt
Initializing final arguments