• Post Reply Bookmark Topic Watch Topic
  • New Topic

var-args  RSS feed

 
suavedeep kaur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi please can anyone explain me the functioning of var-args with an example ???
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
var args can be used to call a method with different number of arguments


 
suavedeep kaur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot nice example
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice example, but you ought to add two warnings.
  • You can get no end of confusion if you also have a method like printStrings(String s2, String s2, String s3)
  • You cannot use varargs where there might be confusion with a method like printStrings(String[] arg)
  •  
    gurneeraj singh
    Ranch Hand
    Posts: 80
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you are really confused that which method will be called, always remember that var-args method is the last option used by java.

    example:

    In above example "method A" will be printed.

    There are some rules related to Var-args do read them aswell.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!