if I have an `Array<String>?` and a `String?...
# announcements
r
if I have an
Array<String>?
and a
String?
and I need to merge the two and return
Array<String>?
- is there a better way than to have a bunch of if-else checking for
null
(if both are null it should return null also)?
m
Copy code
str?.let { array?.plus(it) ?: arrayOf(it) }
r
what if
str == null
but
arr != null
m
Good point, then it becomes even longer:
Copy code
str?.let { array?.plus(it) ?: arrayOf(it) } ?: array
and probably should be hidden as an extension function
r
yea it becomes hard to read, maybe a bunch of if-else isn’t too bad after all
2