• Post Reply Bookmark Topic Watch Topic
  • New Topic

Var arg methods  RSS feed

 
Raghu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to return var arg parameter to any method???

for ex:

public static int... m1(int... x){

return x;
}
[ November 19, 2008: Message edited by: Raghu ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raghu, please check your private messages.
 
Srikanth Nutigattu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
VAR-ARG itself says that it is "Variable Number of Arguments" anywayz

You cannot specify a return value as varargs. Because, even if you think logically, there can be only one return value, so how come there can be a possibility of varargs as a return value.

Moreover, if varargs would have been possible as a return value, how can you assign the return value to multiple variables

So, syntactically as well as logically too varargs as return value is not possible.

if you have multiple values to be returned, better return them as part of an array, or a list for that matter
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that varargs are converted to an array. When you say int ... numbers, it is a bit like saying int[] numbers. But users of the method can write 1, 2, 3 instead of new int[]{1, 2, 3}.

The equivalent to varargs return value would of course be an array.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!