Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

error- ambiguous reference to method

 
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why i am getting error "reference to A is ambiguous, both method A(float...) in Test and method A(double...) in Test match" in this code?
 
Ranch Hand
Posts: 58
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may find this thread useful.
link
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Sebanti
reading that discussion I concluded that var-args in any case have same priority. It doesn't matter wether it is

or

or

with a call
all have same priority. Thats why it is ambigous for compiler to predict the call. Am I right?
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but if it is so, the why this is allowed?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

For objects there are no concepts like narrowing or widening as there are for primitives but only upcasting/downcasting if the 2 belong to the same hierarchy.
For example, this won't work:

Long it's NOT an Integer(they both extend Number but there is no direct link between them in the hierarchy) even if long(the primitive) can be seen as an integer through widening.

This won't work neither:



Best,

Astha Sharma wrote:but if it is so, the why this is allowed?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this code
you are overloading the methods with the same name
so the compiler is unable to search for that specific method

and don't use dot(..) in the method arguments .
class Test
{
void A(int a){
System.out.println("in int");
}
void A(float a){
System.out.println("in float");
}
void A(double a){
System.out.println("in double");
}
public static void main(String[]args)
{
Test a=new Test();
a.A(7);
}
}
copy and run it
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no one is answring my question
I am asking that why this
is allowed while this or this is not allowed?
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic