Hi, Compose Docs mention <https://developer.androi...
# multiplatform
o
Hi, Compose Docs mention that Compose always considers unstable where they are from modules in which the Compose compiler does not run. We put our data classes to KMM module, which is 'another module' for Android. So we should Wrap the classes in UI model classes. Doesn't this break the purpose of KMM module for data classes? Is there an easy way to convert those classes to a stable class?
c
you can annotate those with the
@Immutable
annotation, so that the compiler can process these as stable classes. See screenshot for an example:
o
Thank you very much. Also, what does
Incorrectly annotating a class could cause recomposition to break.
mean? Using only val and immutable collections should be enough for a class to be immutable right?
c
Using only val and immutable collections should be enough for a class to be immutable right?
Yes this is correct, but as the docs specify any class that is declared in a module where the compiler is not run, then the compiler cannot assess that classes stability
this becomes problematic when you are declaring classes in a KMP module where the compose compiler is not running (assuming you arent using compose multiplatform)
o
no I'm not using compose multiplatform. so will annotating data classes with Immutable work? they're all in kmm module and compose compiler is not running.
c
yup, the example I've shown above will ensure that any classes you apply this annotation to will be considered stable by the compiler
o
okay thank you very much
if I didn't use multiplatform at all, what are the situations that I needed to use Immutable annotation? When does compiler cannot know if the class is stable, besides from the another module thing?
c
thats pretty well summarised at the bottom of the docs
o
I missed that sorry. thank you very much for the help
🤘🏼 1