Scala has a weird drawback, that I cannot create a default argument in args
. Here is my latest attempt:
object Main extends java.lang.Object with ScalaObject with App {
override val args:Array[String]=Array(args.toList.headOption.getOrElse("f"))
println("args(0) = " + args(0))
}
Run the code here: http://ideone.com/B20HBA
Exception in thread "main" java.lang.NullPointerException at scala.collection.mutable.ArrayOps$ofRef$.length$extension(ArrayOps.scala:114) at scala.collection.mutable.ArrayOps$ofRef.length(ArrayOps.scala:114) at scala.collection.SeqLike$class.size(SeqLike.scala:106) at scala.collection.mutable.ArrayOps$ofRef.size(ArrayOps.scala:108) at scala.collection.mutable.Builder$class.sizeHint(Builder.scala:69) at scala.collection.mutable.ListBuffer.sizeHint(ListBuffer.scala:45) at scala.collection.TraversableLike$class.to(TraversableLike.scala:628) at scala.collection.mutable.ArrayOps$ofRef.to(ArrayOps.scala:108) at scala.collection.TraversableOnce$class.toList(TraversableOnce.scala:257) at scala.collection.mutable.ArrayOps$ofRef.toList(ArrayOps.scala:108) at Main$delayedInit$body.apply(Main.scala:2) at scala.Function0$class.apply$mcV$sp(Function0.scala:40) at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) at scala.App$$anonfun$main$1.apply(App.scala:71) at scala.App$$anonfun$main$1.apply(App.scala:71) at scala.collection.immutable.List.foreach(List.scala:318) at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32) at scala.App$class.main(App.scala:71) at Main$.main(Main.scala:1) at Main.main(Main.scala)