Default arguments to Scala's main function? -


how work, i've tried , without new keyword:

object main extends app {     override def main (args : array[string] = new array("default argument")) {         println("args(0) = " + args(0))     } } 

http://ideone.com/5aytxy (i have tried other [1, 2] methods think val causing issues)

docs: http://docs.scala-lang.org/sips/completed/named-and-default-arguments.html#default_arguments

ps: should confirm want bound args name; rather var or val. additionally scope needs global within main.

to satisfy intent here (as clarified last comment @alexiv's answer) - keeping field name of args while allowing default value field - can override field, using reference original value prefixed super.:

object main extends app {     override val args: array[string] = if (super.args.isempty) array("default argument") else super.args     println("args(0) = " + args(0)) } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -