allan.conda
10/16/2020, 2:57 AM@Immutable
and read this bit:
And then looked at compose-samplesclasses that only containdata
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:val
@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:
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…