Forums Register Login

varargs doubt

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
thanks a lot Barry
You don't like waffles? Well, do you like this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 514 times.
Similar Threads
What will this program print out? Why?
An example of abstraction in java
Synchronized Blocks
Extends
Method calling
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:25:15.