Pablo
08/20/2024, 4:34 PMif (parameters[i] != null) {
if (parameters[i].isNotEmpty()) {
Why this gives error on .isNotEmpty()? I mean... it's supposed that the != null should about this problem:
Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?Michael Krussel
08/20/2024, 5:08 PMparameters is, but I will assume that the compiler cannot assume that parameters[i] returns the same value every time you call it, so smart cast is not happening.Pablo
08/20/2024, 5:16 PMMichael Krussel
08/20/2024, 5:19 PMparamaters is a String or parameters[i] is a String?
But still the [] operator is a function call and there's no guarantee that it returns the same object every time. Now Kotlin could hard take advantage that String is immutable, but String.get cannot return null so there's no need, so I"m sure parameters is not a String.
It is probably either a List or an Array both of which are not immutable.Pablo
08/20/2024, 5:20 PMPablo
08/20/2024, 5:21 PMMichael Krussel
08/20/2024, 5:21 PMLandry Norris
08/20/2024, 5:55 PMCiaran Sloan
08/20/2024, 8:03 PMval myValue = parameters[i]
if (myValue != null) {
if (myValue.isNotEmpty()) {
// .....
}
}
Or alternatively:
val myValue = parameters[i]
if (myValue.isNullOrEmpty()) {
// ....
}Hristijan
08/21/2024, 4:20 AMCiaran Sloan
08/21/2024, 6:23 AM.let is a functional mapper. If you are not interested in the return value, then that's not its best use case. It should not be a default replacement for a standard null check