• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic