Just a quick question on the @Immutable annotation...
# compose
Just a quick question on the @Immutable annotation. How should we treat things with immutable lists?
Copy code
@Immutable data class Foo(values: List<String>)
in theory, i suppose one could pass a MutableList to the data class, so theoretically it’s not correct to mark this with Immutable. But in practice, we’re only ever passing immutable lists. Has anyone encountered this? (or even use the Immutable annotation)? There is ImmutableList which is part of the compose framework, but these are internal types and not accessible. The other question is are the optimizations from @Immutable even worth worrying about this.
My blog post covers these questions if you haven't seen it. https://medium.com/androiddevelopers/jetpack-compose-stability-explained-79c10db270c8
To quickly answer your questions though 1. The annotation is a agreement you are taking to never do that or else you will end up with incorrect behaviour. 2. ImmutableList is a kotlinx collection, not a Compose one. You can add the kotlinx dependency to use it 3. It depends on how expensive the recomposition you are saving is. Sometimes it's negligible and other times it can be a big saving. We recommend writing a benchmark to measure your performance optimisations. https://developer.android.com/codelabs/android-macrobenchmark-inspect#0
Thanks @Ben Trengrove [G] I was looking for ImmutableList and finding the one in compose 🤦