https://kotlinlang.org logo
#announcements
Title
# announcements
r

rajendhiraneasu

07/13/2017, 10:52 AM
is that shallow copy is possible in kotlin? how come it works with copy()? while using data class?
k

karelpeeters

07/13/2017, 10:54 AM
Please don't crosspost like this.
r

rajendhiraneasu

07/13/2017, 10:54 AM
sorry, i posted in wrong group before so only asked the question in #general
can you please explain the shallow and deep copy in kotlin? i can manage to get data class it works fine for deep copy... but i'm not sure about the shallow copy
k

karelpeeters

07/13/2017, 10:58 AM
Are you sure that data classes do a deep copy? Do you know the difference?
r

rajendhiraneasu

07/13/2017, 10:58 AM
data class Company(var TIN:String, var Size:Int){ } var comp = Company(TIN="12345678910",Size = 100) var compCpy = comp.copy(TIN="123"); comp.Size=90 println("Old Company $comp") println("Copy Company $compCpy")
see here it does the deep copy only
oh okay got it
k

karelpeeters

07/13/2017, 10:59 AM
When copying something with only immutable values (
String
,
Int
, ...) there's no difference.
r

rajendhiraneasu

07/13/2017, 11:01 AM
ok
7 Views