Created
March 23, 2022 12:28
-
-
Save zeraf29/be46ec6601d539736ca7fa5828e75b4e to your computer and use it in GitHub Desktop.
Coursera-kotlin extension function lexture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
val s1: String? = null | |
val s2: String? = "" | |
s1.isEmptyOrNull() eq true | |
s2.isEmptyOrNull() eq true | |
val s3 = " " | |
s3.isEmptyOrNull() eq false | |
} | |
fun String?.isEmptyOrNull() = (this == null || this.isEmpty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
isEmptyOrNull()
Add and implement an extension function 'isEmptyOrNull()' on the type String?. It should return true, if the string is null or empty.