斯卡拉阵列VS矢量 [英] Scala Arrays vs Vectors

查看:164
本文介绍了斯卡拉阵列VS矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

斯卡拉福利局...我很困惑

Scala newb... I'm confused

object myApp extends App {
  println("Echo" + (args mkString " "))
}

ARGS是一个类型数组[字符串],但在scaladoc,数组有没有这样的方法。 mkString是载体的方法,但我没有看到任何两者之间的继承链。所以,我们为什么可以使用mkString方法上ARGS?

"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?

推荐答案

我不是一个专家的Scala(远非如此!),但我想答案是隐式转换(请参阅阶。preDEF )和WrappedArray.scala。

I'm not a scala expert (far from it!) but I think the answer is implicit conversions (see scala.Predef) and WrappedArray.scala.

在特别preDEF有下列隐式转换:

In particular, Predef has the following implicit conversion:

implicit def genericWrapArray [T] (xs: Array[T]): WrappedArray[T] 

和WrappedArray有mkString方法。当斯卡拉找不到一个数组的方法mkString,它寻找一个隐式转换为类型一样。

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 /电流/斯卡拉/ preDEF $的.html

http://www.scala-lang.org/api/current/scala/collection/mutable/WrappedArray.html

这篇关于斯卡拉阵列VS矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆