Kotlin: check for null

How do you check for null in Kotlin?

var myName:String? = null

Using safe call operator ?. and scoping function let:

myName?.let {
    //execute code here
    println(myName)
}

Using an if block:

if(myName!=null){
    //execute code here
    println(myName)
}

Leave a Reply

Your email address will not be published. Required fields are marked *