speed_star
11/17/2020, 8:33 AMnull
property is exists in data class. Should I check for each property like as below? Or there is other good way?
data class Book(val name: String?, val author: String?, val price: Int?)
fun isExistNull(): Boolean {
if (name == null || author == null || price == null) {
return true
}
return false
}
jbnizet
11/17/2020, 12:41 PMreturn (name == null || author == null || price == null)
is sufficient. But other than that, yes, it’s the straightforward way to do it.Nick Johnson
11/17/2020, 10:38 PMname ?: author ?: price ?: true == true
should also work