The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes error- ambiguous reference to method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "error- ambiguous reference to method" Watch "error- ambiguous reference to method" New topic
Author

error- ambiguous reference to method

Astha Sharma
Ranch Hand

Joined: Oct 15, 2011
Posts: 128


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?
Sebanti Sanyal
Ranch Hand

Joined: Nov 07, 2011
Posts: 58

You may find this thread useful.
link
Astha Sharma
Ranch Hand

Joined: Oct 15, 2011
Posts: 128

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

Joined: Oct 15, 2011
Posts: 128

but if it is so, the why this is allowed?
Bogdan Todasca
Greenhorn

Joined: Feb 12, 2012
Posts: 1
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?
Ratnesh Navlakhe
Greenhorn

Joined: Feb 12, 2012
Posts: 1
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

Joined: Oct 15, 2011
Posts: 128

no one is answring my question
I am asking that why this
is allowed while this or this is not allowed?
 
 
subject: error- ambiguous reference to method
 
Threads others viewed
Var-arg doubt
Exam Lab Test 2 Question
Method overloading.
Method specific call.
Reference to method is ambiguous??????
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture