https://kotlinlang.org logo
#compose
Title
# compose
u

谢朋刚

03/29/2024, 3:07 AM
is Array<> in compose stable?
m

Matthew Feinberg

03/29/2024, 3:13 AM
Immutability isn't enforced for arrays, so there are a whole array (no pun intended) of possible hard-to-find bugs that could spring up if someone writes code that mutates the array. Personally, I'd prefer
List<>
for this sort of thing.
u

谢朋刚

03/29/2024, 3:14 AM
so prefer ImmutableList ?
m

Matthew Feinberg

03/29/2024, 6:51 AM
You could, but
List<>
is a read-only interface, so unless you're trying to cast it to other things, just
List<>
is probably what you want (it's what you get if you use
listOf<>(...)
for example.
thank you color 1
s

Stylianos Gakis

03/29/2024, 9:59 AM
Importantly
List
actually unfortunately still is not considered stable for compose’s sake. So either just use ImmutableList for now, or wait for strong skipping mode to be turned on where they will also start inferring List as stable
🙌 1
m

Matthew Feinberg

03/29/2024, 10:00 AM
That's good to know, thank you!
(I don't normally pass List<> directly, and the classes that I use that wrap it are annotated with @Immutable, so I forgot about that)
s

Stylianos Gakis

03/29/2024, 10:03 AM
Then don’t worry about it
m

Matthew Feinberg

03/29/2024, 10:03 AM
Yeah, but I need to not give out wrong information here 😅 so it still matters.
4 Views