mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
- 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
17 lines
400 B
Kotlin
17 lines
400 B
Kotlin
data class A(var x: Int) : Cloneable {
|
|
public override fun clone(): A {
|
|
val result = super.clone() as A
|
|
result.x = 239
|
|
return result
|
|
}
|
|
}
|
|
|
|
fun box(): String {
|
|
val a = A(42)
|
|
val b = a.clone()
|
|
if (a == b) return "Fail: $a == $b"
|
|
if (a identityEquals b) return "Fail: $a identityEquals $b"
|
|
if (b.x != 239) return "Fail: b.x = ${b.x}"
|
|
return "OK"
|
|
}
|