Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

var-args

 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


this prints 1 whereas



this prints some absurd value..why? isnt int boxed to integer here?
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Neha...that was superb
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic