What is the difference between Array and WrappedArray in Scala

后端 未结 1 2026
长情又很酷
长情又很酷 2021-02-13 15:04

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 perfor

相关标签:
1条回答
  • 2021-02-13 15:13

    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.

    0 讨论(0)
提交回复
热议问题