File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading doubt 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 "Overloading doubt" Watch "Overloading doubt" New topic

Overloading doubt

Sanjay Singh
Ranch Hand

Joined: Mar 02, 2006
Posts: 37

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.

Regards, Sanjay Singh
Anastasia Sirotenko
Ranch Hand

Joined: Jul 20, 2009
Posts: 64
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

[SCJP 6.0]
Sanjay Singh
Ranch Hand

Joined: Mar 02, 2006
Posts: 37

Thanks Anastasia, now its crystal clear.
I agree. Here's the link:
subject: Overloading doubt
It's not a secret anymore!