Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how the compiler chooses a method from overloaded methods?

 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this kind of question discussed here many time. search here
 
Emanuele Ghe
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevinn please post here if you find the answer, anyway your code does not compile.

Thanks.
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I couldnt find.can some one help
thanks
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks prithvi
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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

Keep rocking,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic