sonofblip
07/19/2019, 7:14 PM!!
always makes me feel icky
val x: Int? = getAnIntegerOrMaybeANullFromAPlaceO
if (x != null) {
functionThatTakesNonNullableIntegerArgument(x) // won't compile because it thinks x is nullable
functionThatTakesNonNullableIntegerArgument(x!!) // will compile because added !!
} else {
// handle the null case
}
streetsofboston
07/19/2019, 7:16 PMvar x
is a property, not a local variable.
If so, do
x?.let {
functionThatTakesNonNullableIntegerArgument(it)
} ?: theNullCase()
PHondogo
07/19/2019, 7:18 PMsonofblip
07/19/2019, 7:19 PMPHondogo
07/19/2019, 7:19 PMDico
07/19/2019, 7:23 PMx
has a custom getter or it is mutabledave
07/20/2019, 7:57 AM