aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes varargs doubt 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 "varargs doubt" Watch "varargs doubt" New topic
Author

varargs doubt

Carlos G�mez
Ranch Hand

Joined: Sep 06, 2006
Posts: 56
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

Joined: Aug 03, 2002
Posts: 7729
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 ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Carlos G�mez
Ranch Hand

Joined: Sep 06, 2006
Posts: 56
thanks a lot Barry
 
 
subject: varargs doubt