Zoltan Demant
08/09/2022, 10:18 AM@Immutable
, but is implemented as a value class that wraps a domain class (without @Immutable
), does compose still consider it immutable? Code example in thread 🧵Zoltan Demant
08/09/2022, 10:18 AMdata class DomainPerson(
val name: String,
)
@Immutable
interface ComposePerson {
val name: String
}
@JvmInline
value class DomainPersonWrapper(
val domainPerson: DomainPerson,
) : ComposePerson {
override val name
get() = domainPerson.name
}
@Composable
fun Person(person: ComposePerson) {
// Is person still immutable if 'DomainPersonWrapper' is passed in?
}
Filip Wiesner
08/09/2022, 10:27 AM@Immutable
on interface? How can you make sure that some implementation will not be mutable? 🤔Zoltan Demant
08/09/2022, 10:37 AMAlbert Chang
08/09/2022, 10:41 AMAlbert Chang
08/09/2022, 10:43 AMPerson
composable, the stability of DomainPersonWrapper
doesn’t matter and what matters is the stability of ComposePerson
.Zoltan Demant
08/09/2022, 10:46 AMComposePerson
still holds true and thus its immutable?Albert Chang
08/09/2022, 10:53 AMComposePerson
. While it is a contract on child classes, it doesn’t necessarily make its child classes stable. For example if you have a @Composable fun Person(person: DomainPersonWrapper)
, the parameter will be considered unstable.Zoltan Demant
08/09/2022, 10:56 AMDomainPerson : ComposePerson
, DomainPerson would be considered @Immutable as well right? Just trying to make sure my understanding of it is correct 😄Albert Chang
08/09/2022, 10:58 AMAlbert Chang
08/09/2022, 11:00 AMZoltan Demant
08/09/2022, 11:02 AMshikasd
08/09/2022, 11:21 AMshikasd
08/09/2022, 11:24 AMvalue
class passed as an interface will force Kotlin to box anyway, so value
might be useless hereZoltan Demant
08/09/2022, 12:11 PMZoltan Demant
08/10/2022, 4:02 PMshikasd
08/10/2022, 4:08 PMZoltan Demant
08/10/2022, 4:15 PMshikasd
08/10/2022, 4:17 PMZoltan Demant
08/10/2022, 4:18 PMZoltan Demant
08/10/2022, 4:19 PMshikasd
08/10/2022, 4:20 PMZoltan Demant
08/10/2022, 4:24 PMZoltan Demant
08/10/2022, 4:56 PM