Scala newb… I’m confused
object myApp extends App {
println("Echo" + (args mkString " "))
}
“args” is type Array[String], but in the scaladoc, Array has no such method. mkString is a method for Vector, but I don’t see any inheritance link between the two. So why can we use the mkString method on args?
I’m not a scala expert (far from it!) but I think the answer is implicit conversions (see
scala.Predef) and WrappedArray.scala.In particular, Predef has the following implicit conversion:
And WrappedArray has a mkString method. When scala can’t find a mkString method on Array, it looks for an implicit conversion to a type that does.
http://www.scala-lang.org/api/current/scala/Predef$.html
http://www.scala-lang.org/api/current/scala/collection/mutable/WrappedArray.html