Hello, I have some question about stability/immutability for classes.
Here is some example:
data class MyString(
private val stringResId: Int,
private val args: List<MyString>,
) {
@Composable
fun getText(): String {
val mappedArgs: Array<String> = args.map { it.getString() }.toTypedArray()
return stringResource(textResId, *mappedArgs)
}
}
As I understand, I can mark getText function as
@ReadOnlyComposable
, but what about the whole class ? Can I mark it as
Immutable
or
Stable
, or none of these annotations can be applied to this class?
And one more example:
data class MyColor(
private val colorGetter: (@Composable () -> Color)
) {
@Composable
fun getColor(): Color {
return colorGetter()
}
}
Usage
val color = MyColor {
MaterialTheme.colorScheme.primary
}