What is the difference between array and WrappedArray in Scala

I am a little confused in terms of these two collections.

I understand that Scala Array calls the Java API. In this case, what is the role of the wrapped array (and its characteristics)?

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

Thanks!

+5
source share
1 answer

WrappedArray wraps Array to give it extra functionality. It also has many types, while an array extends only serializable and clonable. This allows you to wrap the array so that it can be used in places where some general type of collection is required, such as Seq .

ArrayOps is also noteworthy, which is similar to WrappedArray in that it enriches the array with additional operations. The difference is that operations in ArrayOps return a regular Array , and operations from WrappedArray return a WrappedArray

ArrayOps takes precedence over WrappedArray , so it will be used if one of the types provided by WrappedArray not needed.

+12
source

Source: https://habr.com/ru/post/1263405/


All Articles