Files
kotlin/compiler/testData/codegen/boxWithStdlib/arrays/clonePrimitiveArrays.kt
Alexander Udalov fb958897a9 Introduce kotlin.Cloneable
- Cloneable is a trait with a single protected member 'clone', which is mapped
  to java.lang.Cloneable on JVM
- 'clone' is non-abstract to be able to call 'super.clone()' in the
  implementations. Also if you need your class to be Cloneable, most of the
  time inheriting from Cloneable and calling 'super.clone()' will work
- hack 'super.clone()' in JVM intrinsics and TImpl delegation generation
- make arrays Cloneable, handle 'clone()' calls in the intrinsic

 #KT-4890 Fixed
2014-07-25 21:19:39 +04:00

38 lines
1.3 KiB
Kotlin

import java.util.Arrays.equals
fun box(): String {
val i = intArray(1, 2)
if (!equals(i, i.clone())) return "Fail int"
if (i.clone() identityEquals i) return "Fail int identity"
val j = longArray(1L, 2L)
if (!equals(j, j.clone())) return "Fail long"
if (j.clone() identityEquals j) return "Fail long identity"
val s = shortArray(1.toShort(), 2.toShort())
if (!equals(s, s.clone())) return "Fail short"
if (s.clone() identityEquals s) return "Fail short identity"
val b = byteArray(1.toByte(), 2.toByte())
if (!equals(b, b.clone())) return "Fail byte"
if (b.clone() identityEquals b) return "Fail byte identity"
val c = charArray('a', 'b')
if (!equals(c, c.clone())) return "Fail char"
if (c.clone() identityEquals c) return "Fail char identity"
val d = doubleArray(1.0, -1.0)
if (!equals(d, d.clone())) return "Fail double"
if (d.clone() identityEquals d) return "Fail double identity"
val f = floatArray(1f, -1f)
if (!equals(f, f.clone())) return "Fail float"
if (f.clone() identityEquals f) return "Fail float identity"
val z = booleanArray(true, false)
if (!equals(z, z.clone())) return "Fail boolean"
if (z.clone() identityEquals z) return "Fail boolean identity"
return "OK"
}