!! Not-null Assertion //use it when you are
sure the value is notnull
//throws
nullpointerexception if the value is found to be null
?.let{}
safe call with let
?. Safe call operator
Val name:
String = null
By
default kotlin not support nullable.
If we
want to assign null we can use -> Val name: String? = null
?.let{} safe call with let
//1.
returns the length if the name is not null else return null
//2.
Name?.let{//It Executes the block only if the name is notnull
Println("")
}
?: Elvis
// when
we have a nullable reference name, we can say "is name is not
null",use it ,
//otherwise
use some non nullable value
- Val nameLen=if(name!=null)
Name.length
Else
-1
Or
Val leng = name?.length?: -1