Is there a way to use the default value on a non-optional parameter when null is passed?
问题 For example, if I have the following data class: data class Data( val name: String = "", val number: Long = 0 ) And functions that can return null : fun newName(): String? {} fun newNumber(): Long? {} I know I can use the following to use the value of the functions if they are not null : val newName = newName() val newNumber = newNumber() val data = Data( if (newName != null) newName else "", if (newNumber != null) newNumber else 0 ) But is there a way to just use the default value specified