• 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

Doubt in Overloading

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


The error message comes for the comment line as " Ambiguious for the type overload" .
Now , if I pass the explicit values , no error comes. But ambiguity rises as i pass the variables.
What is the difference between this two method calling.

thanks
Abhijit
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because boxing or unboxing is required to satisfy either of the signatures the compiler doesn't know which method it should call.
 
Abhijit Das
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello, Ian
I am not cleared. Why it is not automatically unboxed or boxed for method invocation. If I comment either of methods, then it is working.

Thanks
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Ian has mentioned already,

for

ob.sum(10,20)

the compiler is passed with implied 2 int primitives. Therefore, the compiler knows which method to call, which is the

sum(int a, int b)

However, for the

ob.sum(x,y);

you passed an int and and Integer. The compiler doesnt know which of the 2 methods to call:

sum(int a, int b)
or
sum(Integer a ,Integer b)

If you are still confused, try think like a compiler. If you are the compiler, how you know which of the 2 overloaded methods would you call if you are given

ob.sum(x,y)

?
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are these examples of overloading,
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic