I have a class that is marked `@Immutable` but co...
# compose
v
I have a class that is marked
@Immutable
but compose metrics reports it as unstable. Am I doing something wrong here? I think this only started happening when I refactored the class to a shared package
Copy code
package app.shared

@Immutable
data class MyImmutableClass(val foo: Foo)
Copy code
package app.main

@Composable
fun MyComposable(param: MyImmutableClass) {...}
Results in the following metrics:
Copy code
restartable fun MyComposable(
  unstable param: MyImmutableClass
)
Resolved! I had to add androidx.compose.foundation to the shared package and import
androidx.compose.runtime.Immutable
instead of
javax.annotation.concurrent.Immutable
which Android Studio recommends first 😄
s
In case you weren't aware, you can make sure it won't suggest
javax.annotation.concurrent.Immutable
by putting it the list found at Settings → Editor → General → Auto Import → Exclude from auto-import […]. I've found this very useful for Compose. simple smile