This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why does this method call compile with only one argument ?

 
Harry Henriques
Ranch Hand
Posts: 206
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because String... is a var-arg which is a convenience for passing an array.

So if you do



The compiler will turn it into



which is a valid String array.

If you omit this argument completely as in your example, the compiler does this:



Which is a 0 sized String array and perfectly legal.
 
Salil Vverma
Ranch Hand
Posts: 255
Hibernate Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Harry,

... operator represents 0 or more arguments . In this case the function can be called in various formats.. I believe, the below code would clear your doubt.




The output would be

The array elements are -
21 22
The array elements are -
20 30 40
The array elements are -
1 2 3 4
The array elements are -

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic