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 var-args Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "var-args" Watch "var-args" New topic


Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521

this prints 1 whereas

this prints some absurd value..why? isnt int boxed to integer here?

scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later" someone unknown
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
because second time you are passing an object(primitive int array) not an array of objects(class Integer) so, I think its giving you the address of the int[] object but when you pass Integer[] object you have a new integer at every index and the class' tostring method returns the value hold in the object.

SCJP 1.6 96%
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
Thanks Neha...that was superb
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521

and why do i get a warning here? but not when i use static void m(Object[] o) ?

and here i thught the output to be c because according to a rule var-args are chosen if no option is left....but output is 1

is this becasue of being specific...that is Object... is more specific than Object afterall Object... is an Object[] and we are passing an Integer[] /???/ too much confusion....
jQuery in Action, 2nd edition
subject: var-args
Similar Threads
About Array reference assignments for One-D arrays
method with array parameter
Advanced overloading
hashCode and equals