Łukasz Gendek
09/05/2023, 9:25 AMif (a.city != null) city = a.city!!
in a kotlin idiomatic way?Sam
09/05/2023, 9:26 AMa.city?.let { city = it }
. Not sure how much I like it, though.Goetz Markgraf
09/05/2023, 9:30 AMa.city
could have been mutated after the check but before the access, resulting in a NullPointerException.
The suggestion by @Sam is betterSam
09/05/2023, 9:30 AMcity = a.city ?: city
, which should achieve the same effect as long as reassigning city
doesn’t have side effectsGoetz Markgraf
09/05/2023, 9:31 AM