Smallville7123
04/15/2019, 2:49 PMCloneable
as i cant find it in the docs nor in the search thing at kotlinlang.orgribesg
04/15/2019, 2:50 PMCloneable
is but every data class
has a copy
methodfred.deschenes
04/15/2019, 2:51 PMjava.lang
Smallville7123
04/15/2019, 2:51 PM.clone()
method in alot of java classesSmallville7123
04/15/2019, 2:51 PMSmallville7123
04/15/2019, 2:52 PMkotlin.Cloneable
does not existfred.deschenes
04/15/2019, 2:52 PMkarelpeeters
04/15/2019, 2:52 PMSmallville7123
04/15/2019, 2:54 PMSmallville7123
04/15/2019, 2:55 PMvar x = 1
fun a() {
var y = x
y = 6
println(x)
println(y)
}
a()
shouldnt x be modified such that y and x have the same value?karelpeeters
04/15/2019, 2:56 PMkarelpeeters
04/15/2019, 2:57 PMx = y
means "take the value that's in y
and put it in x
too". The boxes themselves, x
and y
, stay independent.Smallville7123
04/15/2019, 2:58 PMy
would obtain the value of x
and not the reference to x
itself?karelpeeters
04/15/2019, 2:58 PMSmallville7123
04/15/2019, 2:58 PMSmallville7123
04/15/2019, 3:01 PMclone()
i would do this? fun clone(): LinkedList<T> {
val tmp = LinkedList<T>()
tmp.head = head
return tmp
}
if so would fun clone(): LinkedList<T> = LinkedList<T>().head = head
also work?karelpeeters
04/15/2019, 3:02 PMdreamreal
04/15/2019, 3:03 PMkarelpeeters
04/15/2019, 3:03 PMSmallville7123
04/15/2019, 3:07 PMval tmp = LinkedList<T>()
forEach { tmp.append(it!!) }
return tmp
karelpeeters
04/15/2019, 3:08 PM!!
, but yeah.Smallville7123
04/15/2019, 3:08 PMSmallville7123
04/15/2019, 3:09 PMSmallville7123
04/15/2019, 3:09 PMkarelpeeters
04/15/2019, 3:10 PMT
, and users can make it nullable if they want, like in your example String?
. The list code itself doesn't need to concern itself with nullability.Smallville7123
04/15/2019, 3:10 PM