• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Overloading doubt

 
Ranch Hand
Posts: 37
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


In the above code compilation fails at Line4. Its says:

The method doStuff(int, float, char) is ambiguous...



But Line4 compiles fine. I am bit confused here why Line3 compiles but not Line4.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems i figured this after changing line three to

I think it is because at line three second arg is 1 which is int value, and as there is no method for (Integer, Integer, Character) or (int, int, char) it is promoted to float, but it is not possible to promote and then autobox, so the primitive method is called for (int,float,char).
But at line 4 the value can be autoboxed to Integer, or other values can be unboxed to primitives (and in my example the same thing) - so here compiler goes mad.

and if you change line 4:

just because the only possibke change here is promoting byte to int, and no boxing after that is possible, so other arguments go outboxed and primitive method for (int, float, char) is called
 
Sanjay Singh
Ranch Hand
Posts: 37
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anastasia, now its crystal clear.
 
The airline is called "Virgin"? Don't you want a plane to go all the way? This tiny ad will go all the way:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic