• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

varargs doubt

 
Carlos G�mez
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers,

what is the difference between the next methods ?

public void method1(int... a){} // 1
public void method2(int[]... a){} // 2
public void method3(int... a[]){} // 3

why method "method3" does not compile ?

Thanks in advance
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After the "..." must follow a parameter name. The parameter's type must come before the "...". So (int... a[]) is illegal. The legacy inherited from C of writing [] after the parameter name does not work for var args.

So (int... a) means an indefinite list of ints presented in an array int a[],
(int[]... a) means an indefinite list of int arrays presented in an array int[][] a)

Try this:

[ December 08, 2006: Message edited by: Barry Gaunt ]
 
Carlos G�mez
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot Barry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic