@here: Quick question about isNullOrEmpty()...this...
# announcements
m
@here: Quick question about isNullOrEmpty()...this contrived-but-simplified example doesn't seem like it should require the bang-bang to compile...yet it does:
Copy code
val someProperty = if (id.isNullOrEmpty())
                "Something"
            else
                padSomeProperty(id)
Note: id is a String? and fun padSomeProperty( sp: String ) parameter is not nullable. But the assignment snippet above results in this compile error:
Error:(16, 32) Kotlin: Type mismatch: inferred type is String? but String was expected
Replacing if (id.isNullOrEmpty()) with if (id == null) works, but isNullOrEmpty() is the better call due to checking for zero-length as well if not null, but short-circuiting if it IS null. So... ...why do I have to change the call to this:
padSomeProperty(id!!)
? Thanks in advance for any help. simple smile