问题描述
我对这两个系列感到有些困惑.
I'm a bit confused in terms of those 2 collections.
我知道Scala的Array会调用Java API.在这种情况下,包装阵列的作用是什么(及其性能特征)?
I understand that Scala's Array calls Java API. In such a case, what's the role of a Wrapped Array (and its performance characteritics)?
http://www.scala-lang. org/api/current/scala/collection/mutable/WrappedArray.html
谢谢!
推荐答案
WrappedArray
包装Array
为其提供了额外的功能.它也有很多类型,而数组仅扩展可序列化和可克隆,这允许将数组包装起来,因此可以在需要某些通用集合类型(例如Seq
)的地方使用.
WrappedArray
wraps an Array
to give it extra functionality. It also have a bunch of types while array extends only serializable and cloneable, This allows an array to be wrapped so it can be used in places where some generic collection type like Seq
is required.
ArrayOps
也是值得注意的,它与WrappedArray
相似,因为它通过额外的操作丰富了Array.区别在于ArrayOps
中的操作返回常规Array
,而WrappedArray
中的操作返回WrappedArray
Also notable is ArrayOps
Which is similar to WrappedArray
in that it enriches an Array with extra operations. The difference is that Operations inArrayOps
return a regular Array
while operations from WrappedArray
return a WrappedArray
ArrayOps
的优先级高于WrappedArray
,因此将使用它,除非需要WrappedArray
提供的一种类型.
ArrayOps
has priority over WrappedArray
so it will be used unless one of the types provided by WrappedArray
is needed.
这篇关于Scala中的Array和WrappedArray有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!