Sudhir Singh Khanger
07/15/2019, 4:10 AMif (nullableIntOne ?: 0 < nullableList?.size ?: 0) {
// some code 1
} else {
// some code 2
}
I can't compare nullable types. So what is the likelihood of above code breaking. How can I mitigate it?Josh Feinberg
07/15/2019, 4:14 AMSudhir Singh Khanger
07/15/2019, 4:29 AMgildor
07/15/2019, 5:46 AMgildor
07/15/2019, 5:47 AMgildor
07/15/2019, 6:22 AMoperator fun Int?.compareTo(other: Int?): Int {
val a = this ?: 0
val b = other ?: 0
return a.compareTo(b)
}
But I wouldn’t recommend to do that! Because this 0
is not universal default, what should be bigger -1 or null?gildor
07/15/2019, 6:23 AMSudhir Singh Khanger
07/15/2019, 9:08 AM