For example, if I have the following data class:
data class Data(
val name: String = \"\",
val number: Long = 0
)
And functions that ca
You can define a companion object for your data class and overload its invoke operator to use default values when null
is passed:
data class Data private constructor(
val name: String,
val number: Long
) {
companion object {
operator fun invoke(
name: String? = null,
number: Long? = null
) = Data(
name ?: "",
number ?: 0
)
}
}