aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading with Var-args and Boxing Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloading with Var-args and Boxing Doubt" Watch "Overloading with Var-args and Boxing Doubt" New topic
Author

Overloading with Var-args and Boxing Doubt

Srividhya Kiran
Ranch Hand

Joined: Feb 17, 2008
Posts: 166
Hi

Please help me with this code....

class EasyOver
{
public static void main(String args[])
{
float f=10f;
Long l=10l;
go(l);//line 1
go(f);//line 2
}
static void go(long... i)//line 3
{
System.out.println("long");
}
static void go(double... d)//line 4
{
System.out.println("var args double");
}
static void go(float... d)//line 5
{
System.out.println("var args float");
}
}

I am getting the following compiler error

at line 1: reference to go is ambiguous, both method go(double...) in
EasyOver and method go(float...) in EasyOver match
go(l);

at line 2: reference to go is ambiguous, both method go(double...) in
EasyOver and method go(float...) in EasyOver match
go(f);

My Question is:

1. when I make call to go() in line 1 it shld call go(long... l) right? why it gives me an error.

2. In line 2 I dont understand why I get the compiler error because 'f' is a float variable and it shld call go(float... f) right?

but when I change the code to the following I dont get any compiler error

class EasyOver
{
public static void main(String args[])
{
float f=10f;
Long l=10l;
go(l);//line 1
go(f);//line 2
}
static void go(long... i)//line 3
{
System.out.println("long");
}
static void go(Double d)//line 4
{
System.out.println("var args double");
}
static void go(Float d)//line 5
{
System.out.println("var args float");
}
}

I get the o/p
long
var args float

Please help me ranchers

Thanks
Srividhya
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Overloading with Var-args and Boxing Doubt