December 2017
Intermediate to advanced
260 pages
7h 34m
English
Many times we simply write an if condition to handle null check and return some static value if it is null. Kotlin has a solution to this stereotype code as well. It has an Elvis operator. An Elvis operator returns the alternate value if the object is found to be null:
var fileName:String?=null val file= File(fileName?:"untitled.txt")
The preceding code will create a file with the name untitled.txt if the fileName string object is found null at the time of creating the file.
Read now
Unlock full access