Philip Dukhov
02/12/2021, 3:58 PMdata class
to have non optional field, but to be able to initialize it with a nil, which will be replaced by a default value. Something like this:
data class Text(val text: String) {
constructor(textNullable: String?) : this(textNullable ?: "", nullable)
}
It works well on native, but on JVM I got following error:
Platform declaration clash: The following declarations have the same JVM signature (<init>(Ljava/lang/String;)V):
constructor Text(text: String) defined in ...
constructor Text(textNullable: String?) defined in ...
Any way I can bypass it? I think I could replace data class
with class
to remove the default constructor, but in this case I’ll lose other data class advantages, like copy(...)
randomcat
02/12/2021, 3:59 PMfun Text(text: String?) = Text(text ?: "")
as a separate functionNir
02/12/2021, 4:06 PMNir
02/12/2021, 4:07 PMNir
02/12/2021, 4:07 PMandylamax
02/12/2021, 4:08 PMdata class Text(val text: String="")
Nir
02/12/2021, 4:09 PMrandomcat
02/12/2021, 4:09 PMNir
02/12/2021, 4:10 PMrandomcat
02/12/2021, 4:10 PM