my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how the compiler chooses a method from overloaded methods? 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 "how the compiler chooses a method from overloaded methods?" Watch "how the compiler chooses a method from overloaded methods?" New topic
Author

how the compiler chooses a method from overloaded methods?

kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87

in occasions like this when there is no exact match how does the compile choose one method?
what does the compiler take in to account when saying that the call to method is "ambiguous"(is it the number of widening operations)?
thanks
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

this kind of question discussed here many time. search here
Emanuele Ghe
Ranch Hand

Joined: Feb 04, 2009
Posts: 111
Kevinn please post here if you find the answer, anyway your code does not compile.

Thanks.


SCJP6 with score 90%. I am conscious of my ignorance and ready to learn from everyone.
kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87
I couldnt find.can some one help
thanks
kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87
Emanuele Ghe wrote:Kevinn please post here if you find the answer, anyway your code does not compile.

Thanks.

yeah it doesnt compile.
thanks
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

http://www.coderanch.com/t/241415/Programmer-Certification-SCJP/certification/Overloaded-Method-Call#1124087

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

understand? I ask you one question

you will get compilation error[ambiguous eference to a method] at this statement * m(c, c); * . to remove error you have to modify this statement. how will you do that?
kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87
Seetharaman Venkatasamy wrote:understand? I ask you one question

you will get compilation error[ambiguous eference to a method] at this statement * m(c, c); * . to remove error you have to modify this statement. how will you do that?


thanks a lot
compiles
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hello,

Snippet taken from JLS and your code snippet where the ambiguity has appeared



This is where the ambiguity is happening. That's why you have to change like this


Because compiler is unable to decide and such a situation is causing ambiguity.

Hope this helps,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87
thanks prithvi
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hello,

Mate you are always welcome. From this we are learning also.

Keep rocking,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how the compiler chooses a method from overloaded methods?