Someone know why `freeze()` isn't part of the stdl...
# multiplatform
s
Someone know why
freeze()
isn't part of the stdlib-common? Would be useful in multiplatform common code.
m
freeze()
is a no-op on JVM/JS so I guess this is why. It's pretty easy to do your own version though
You can use https://github.com/touchlab/Stately if you want to have an implementation
s
Thanks for the link @mbonnin! I had some multiplatform code with kotlin 1.3 that used a bunch of
@SharedImmutable
annotations on some `val`s in
data
classes and
enum
classes, but it seems it doesn't work anymore with kotlin >= 1.4. I needed those annotations for the iOS clients of my library as the data returned is transfering across other threads. Is calling
.freeze()
at a few strategic places the way to go or is there a more "standard" way to replace these
@SharedImmutable
?
m
TBH at this point, I'd start looking into Kotlin 1.6 and the new memory model
All the freeze() is going away
Unless this is code you in in production right now in which case I don't know
Maybe you can refactor your code to have
@SharedImmutable
as top level properties instead of data classes properties
Or calling
.freeze()
in the "appropriate" place would work too
👍 1
s
I think "long term" your suggestion makes a lot of sense. However, yes this is code already in production, so I'm a bit reluctant (to use 1.6). Also, I don't have much time right now, so I think I will bite the bullet and use a
.freeze()
multiplatform implementation for now. I don't understand why
@SharedImmutable
doesn't work anymore though. It doesn't seem documented anywhere.