• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array Vs VarArgs

 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, The following question is from whizlabs..Why I am getting compile error as mentioned in the comments ?

 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here, the base address of array i.e., first element of array's address referred by "i" is passed as argument in test()...

What the varargs expects is multiple arguments which is of "int" data type...

It has to be passed like

test(1,2,3,4)
(or)
test(1,2,3,4,5)
(or)
Likewise upto n times...
 
Sudhakar Sharma
Ranch Hand
Posts: 71
Eclipse IDE Java
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harikrishna Gorrepati wrote:Hi, The following question is from whizlabs..Why I am getting compile error as mentioned in the comments ?


Hi,

Because there is not the matching method signature.
The rule is Integer can be unboxed to an int, but Integer[] cannot be unboxed to an int[].
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic