Kotlin common expressions let,?:, as?,?.,!!
let
a?.let{it}
When a is null, do nothing
When a is not null, execute the statement in the braces (it must not be null)
object.let{
it.todo() //Use it in the function instead of the object object to access properties and methods
}
object?.let{
it.todo() //The let function will only be executed if the object is not null
}
?:
a ?: b
When a!=null, execute a
When a==null, execute b
as?
a as? b
if a is b, then a as b
null if a is not b
?.
a?.b()
if a != null, then ab()
null if a == null
!!
a!!
If a!=null, execute a
If a==null, throw a null pointer