• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

varagrs

 
Mohtashim Shaikh
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We cannot have two varags and a string passed in the same method. If not why?

test1(1,2,3,x,y,z,3.0)


void test1(int... x, char... z, double d)
{
.....
...
}
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The restriction on variable arguments is that you can only have one single var-arg parameter, and it must be the last argument. That's to make it easier/possible for the compiler to work out which ones are part of the variable parameters. For example:
Now...is that 3 arguments in a and none in b? Or 2 in a and 1 in b? Or what?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only have ONE variable argument list in a method, and it must be the last one in the declaration.

type doesn't matter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic