Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Copy-a-string/Scala/copy-a-string.scala
Normal file
13
Task/Copy-a-string/Scala/copy-a-string.scala
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
val src = "Hello"
|
||||
// Its actually not a copy but a reference
|
||||
// That is not a problem because String is immutable
|
||||
// In fact its a feature
|
||||
val des = src
|
||||
assert(src eq des) // Proves the same reference is used.
|
||||
// To make a real copy makes no sense.
|
||||
// Actually its hard to make a copy, the compiler is too smart.
|
||||
// mkString, toString makes also not a real copy
|
||||
val cop = src.mkString.toString
|
||||
assert((src eq cop)) // Still no copyed image
|
||||
val copy = src.reverse.reverse // Finally double reverse makes a copy
|
||||
assert(src == copy && !(src eq copy))// Prove, but it really makes no sense.
|
||||
Loading…
Add table
Add a link
Reference in a new issue