Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable-arguments

 
akshay dev
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can anyone tell me the declaration rules for var-args. i currently have sierra and bert scjp 6.0 guide
but its written in somewhat i really can't understand.
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akshay dev wrote:hi,
can anyone tell me the declaration rules for var-args. i currently have sierra and bert scjp 6.0 guide
but its written in somewhat i really can't understand.

Welcome to CodeRanch!

Can you be a little more specific about what is exact part you are finding difficult to understand? Also, you can refer Java Language Specification.
 
akshay dev
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i didn't understood " the var-args must be the last parameter in the method's signature , and you can have only one var-arg in a method ".
 
Kevin Florish
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ashkay

The following may help with your understanding of var-args Variable-Length Arguments
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akshay dev wrote:i didn't understood " the var-args must be the last parameter in the method's signature


That means this:




, and you can have only one var-arg in a method ".


That means this:


I think the reason for these rules is that it makes it a lot easier for the compiler to match a signature when we call foo(arg1, arg2, arg3, arg4, arg5) if it knows that only the last arguments can possibly go with a varargs parameter. If these rules weren't in place, there would be a lot more potentially valid signature that could match and it would be difficult or impossible for the compiler do determine which one was correct.

 
akshay dev
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you all
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic