• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overloading with Var-args and Boxing Doubt

 
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic