poohbar
06/14/2019, 3:28 PM(argument as List<String>?)?.orEmpty()
intellij is highlighting the ?.
as "This call is useless"
why is it useless?tddmonkey
06/14/2019, 3:30 PMorEmpty()
works on a nullable listpoohbar
06/14/2019, 3:30 PMnull
blows my mindtddmonkey
06/14/2019, 3:34 PMAntónio Bastião
06/16/2019, 10:04 AMpindab0ter
06/17/2019, 12:40 PM?.
is useless as the .orEmpty()
-function (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/or-empty.html) is called on an instance of type Collection<T>?
or List<T>?
and returns an empty list in the case that the collection or list is null
.
Adding the safe call operator would cause orEmpty()
to only be called when it is not null, which would be useless since the function’s purpose is to do something when it’s reciever is null.