- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
The SLS on Array.copy vs. System.arraycopy
Tue, 2009-10-20, 23:50
According to the SLS 12.3.4 (p. 140 of the version that Adriaan posted earlier),
System.arraycopy will not work for Scala’s polymorphic arrays because of
their different representation. One should instead use method Array.copy
which is defined in the companion object of class Array.
Presumably System.arraycopy does work for Scala array now (tho' we
might still prefer Array.copy).
Cheers,
Miles
Wed, 2009-10-21, 00:57
#2
Re: The SLS on Array.copy vs. System.arraycopy
>>>>> "Nils" == Nils Kilden-Pedersen writes:
Nils> Does array.clone work in 2.8?
I don't know if it's a bug or a feature, but in 2.8 toArray copies
arrays:
Welcome to Scala version 2.8.0.r19127-b20091018090027 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_15).
scala> Array(0)
res0: Array[Int] = Array(0)
scala> res0.toArray
res1: Array[Int] = Array(0)
scala> res0(0) = 99
scala> res0
res3: Array[Int] = Array(99)
scala> res1
res4: Array[Int] = Array(0)
Wed, 2009-10-21, 13:27
#3
Re: The SLS on Array.copy vs. System.arraycopy
Which was related to a ticket I opened a while ago, where passing an array as a vararg resulted in changes made to the array received not being reflected in the passed array. That was fixed, though.
On Tue, Oct 20, 2009 at 9:49 PM, Seth Tisue <seth@tisue.net> wrote:
--
Daniel C. Sobral
Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
On Tue, Oct 20, 2009 at 9:49 PM, Seth Tisue <seth@tisue.net> wrote:
>>>>> "Nils" == Nils Kilden-Pedersen <nilskp@gmail.com> writes:
Nils> Does array.clone work in 2.8?
I don't know if it's a bug or a feature, but in 2.8 toArray copies
arrays:
Welcome to Scala version 2.8.0.r19127-b20091018090027 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_15).
scala> Array(0)
res0: Array[Int] = Array(0)
scala> res0.toArray
res1: Array[Int] = Array(0)
scala> res0(0) = 99
scala> res0
res3: Array[Int] = Array(99)
scala> res1
res4: Array[Int] = Array(0)
--
Seth Tisue @ Northwestern University / http://tisue.net
lead developer, NetLogo: http://ccl.northwestern.edu/netlogo/
--
Daniel C. Sobral
Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
On Tue, Oct 20, 2009 at 5:50 PM, Miles Sabin <miles@milessabin.com> wrote: