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

allan.conda

10/16/2020, 2:57 AM
Trying to annotate with data classes with
@Immutable
and read this bit:
data
 classes that only contain 
val
 properties that do not have custom getters can safely be marked as Immutable if the types of properties are either primitive types or also Immutable:
And then looked at compose-samples
Copy code
@Immutable
data class Episode(
    @PrimaryKey @ColumnInfo(name = "uri") val uri: String,
    @ColumnInfo(name = "podcast_uri") val podcastUri: String,
    @ColumnInfo(name = "title") val title: String,
    @ColumnInfo(name = "subtitle") val subtitle: String? = null,
    @ColumnInfo(name = "summary") val summary: String? = null,
    @ColumnInfo(name = "author") val author: String? = null,
    @ColumnInfo(name = "published") val published: OffsetDateTime,
    @ColumnInfo(name = "duration") val duration: Duration? = null
)
I have data classes with
Date
. Anyway it should still be safe to annotate as long as I’m sure it doesn’t get changed right? Also, I have states with single-time events:
Copy code
data class Event<out T>(val content: T) {
    var consumed: Boolean = false
        private set

    fun consume(): T? =
        if (consumed) {
            null
        } else {
            consumed = true
            content
        }
}
I guess I can’t use `@Immutable`for such state classes…
Wondering about enums as well (saw some examples for sealed classes)
3 Views