What is the difference between Array and WrappedArray in Scala

吃可爱长大的小学妹 提交于 2020-08-04 02:28:17

问题


I'm a bit confused in terms of those 2 collections.

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

Thanks!


回答1:


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.

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 has priority over WrappedArray so it will be used unless one of the types provided by WrappedArray is needed.



来源:https://stackoverflow.com/questions/41881942/what-is-the-difference-between-array-and-wrappedarray-in-scala

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!