| Author |
var arg
|
Singh Himanshu
Greenhorn
Joined: Jul 29, 2010
Posts: 1
|
|
'Its legal to have other parameters in a method that uses a var arg.'
does the above statement means
please explain.
|
 |
Raymond Tong
Ranch Hand
Joined: Aug 15, 2010
Posts: 156
|
|
Singh Himanshu wrote:'Its legal to have other parameters in a method that uses a var arg.'
does the above statement means
please explain.
http://lmgtfy.com/?q=java+varargs+tutorial
Varargs should be the last parameter
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1047
|
|
Singh Himanshu wrote:'Its legal to have other parameters in a method that uses a var arg.'
does the above statement means
please explain.
the var-args will always be the last.
and also not both the args in the method are var-args.
|
SCJP6.0,My blog Ranchers from Delhi
|
 |
Vishal Kashyap
Ranch Hand
Joined: Aug 07, 2010
Posts: 73
|
|
Singh Himanshu wrote:'Its legal to have other parameters in a method that uses a var arg.'
does the above statement means
please explain.
Yes, definitely more than one parameters can exist with one var-args in a method but one and only limitation is var-args must be the last parameter in the method declaration.
|
MCSA 2003 | Preparing For OCPJP/SCJP6
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1047
|
|
Vishal Kashyap wrote:
Yes, definitely more than one parameters can exist with one var-args in a method but one and only limitation is var-args must be the last parameter in the method declaration.
No...we can only have one var-args argument in a method, and that should be the last.
more then one var-args will give compile time error as "too-many var-args"
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
shanky sohar wrote:. . . No...we can only have one var-args argument in a method, and that should be the last. . . .
That is the same as the previous poster said.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
Singh Himanshu, welcome to JavaRanch
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1047
|
|
Campbell Ritchie wrote:
shanky sohar wrote:. . . No...we can only have one var-args argument in a method, and that should be the last. . . .
That is the same as the previous poster said.
hmmm..Yes,you are right..last time i am not able to understand that.
|
 |
Vinoth Kumar Kannan
Ranch Hand
Joined: Aug 19, 2009
Posts: 276
|
|
and moreover, isnt int..x,int...y redundant?!
int...x itself means any number of int parameters.
infinity+infinity=infinity => so why not just use 'infinity' once
|
OCPJP 6
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
|
And what about foo(String ... words, int ... numbers) . . .? That is also prohibited by the rule about one varargs parameter.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
Vinoth Kumar Kannan wrote:and moreover, isnt int..x,int...y redundant? . . .
No it isn't; it is simply impossible to tell which the last int for x is and which the first int for y is.
|
 |
Vinoth Kumar Kannan
Ranch Hand
Joined: Aug 19, 2009
Posts: 276
|
|
Campbell Ritchie wrote:No it isn't; it is simply impossible to tell which the last int for x is and which the first int for y is.
Thats a reason why Java prevented more than 1 var-args for a method.
What I wanted to say was...
int... x => any number of integers
int... y => any number of integers
Even if more than 1 var-arg was allowed for a method, you wouldn't want to use int... x,int... y , because int... x simply means the same and would satisfy the requirement as well.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Vinoth Kumar Kannan wrote:and moreover, isnt int..x,int...y redundant?!
No. For the method there is a real difference between x and y. So int... x, int... y is definitely not the same as int... xy.
Multiple varargs may sometimes be easy to detect (like String... s, int... i), but in too many cases (e.g. Object... o, String... s -- any String is also an object) there is just too much ambiguity. That's why only one is allowed.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: var arg
|
|
|