Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variable length argument list. Java 5.0

 
Rupak Khurana
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is valid :-

public void foo (int token, String ... strs) {}

however the next line is not.. why not...?

public void foo (String ... strs, int token) {}.. The compiler just reports "; expected at line ". The variable strs is treated as an array anyways and can hold zero or more arguments. So this syntax should be valid too....

any comments....
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A method can only have one variable length argument and it must be the last in the method signature. You can read more about this at

http://java.sun.com/j2se/1.5.0/docs/guide/language/varargs.html
Marcus
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic