Add and implement an extension function 'isEmptyOrNull()' on the type String?. It should return true, if the string is null or empty
fun main(args: Array<String>) {
val s1: String? = null
val s2: String? = ""
s1.isEmptyOrNull() == true
s2.isEmptyOrNull() == true
val s3 = " "
s3.isEmptyOrNull() == false
}
infix fun <T> T.isEqualTo(other: T) {
if (this == other) println("OK")
else println("Error: $this != $other")
}
fun String?.isEmptyOrNull() = this == null || isEmpty()
Yorumlar
Yorum Gönder