NULL security
An important feature of the Kotlin system is its commitment to eliminate null references. Avoid any NPE (nullpointerexception) exceptions.
Defining a variable that is allowed to be empty in Kotlin is not allowed to be defined in an empty way.
var a:string = "ABC"//Cannot be an empty
var b:string? = "ABC"//Can be empty
b.length//may error
//second one more than the first one '? '
Null value Check
Val L = if (b! = null) b.length () else-1
Secure call
B?. Length ()
If B is empty, returns without calling the length () Elvis operator
?:
Val L = b.length ()?: 1
If B is empty, then l=-1.
Check function parameters generally write this:
Fun foo (node:node): String? {
val parent = Node.getparent ()?: return null
val name = Node.getname ()?: Throw IllegalArgumentException ("name E xpected ")
//...
}
!! Operator
Val b:string? = null
val L = b!!. Length
Safe conversion
Val aint:int? = A as? Int