File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes WIDENING and VAR-ARG 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 "WIDENING and VAR-ARG" Watch "WIDENING and VAR-ARG" New topic
Author

WIDENING and VAR-ARG

Bob Wheeler
Ranch Hand

Joined: Apr 24, 2009
Posts: 317
Source: ExamLab from Deveka (practise exam) - Exercise 9


Output: aebcd

I was surprised that the call with the int array goes to the var-arg method and not the object method. I thought var-arg is always used last???
But not here? I mean, an array is an object and that int array could be widened to an object. And because widening is before var-arg ...
Where is my error? (same for the Integer array)

Thanks
cheers
Bob

SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

First of I think you pointed out the wrong method that's called. Try this



Now the method with Object argument will be called. when you create a var-arg method, then it is converted into a normal array accepting method (I think you must be knowing that already). Here var-arg is chosen because it is a direct match to the int... method. So that's why the compiler didn't go for widening...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Bob Wheeler
Ranch Hand

Joined: Apr 24, 2009
Posts: 317
Ankit Garg wrote:...
Now the method with Object argument will be called. when you create a var-arg method, then it is converted into a normal array accepting method (I think you must be knowing that already). Here var-arg is chosen because it is a direct match to the int... method. So that's why the compiler didn't go for widening...

Yeah, I SHOULD have known that
But at least I know it now.

Thanks a lot
Bob
 
wood burning stoves
 
subject: WIDENING and VAR-ARG