November 2018
Intermediate to advanced
388 pages
9h 5m
English
In Kotlin, we can declare a variable to hold a null value using the nullable type.
Let's write a program to check whether the given input is Web. If it is, it should return Web Development. If not, it should return an empty string.
Consider the code for 11_NullType.kts:
fun checkInput (data: String) : String { if(data == "Web") return "Web development" return ""}println(checkInput ("Web"))println(checkInput ("Android"))
The output is as follows:

So far, so good. Let's say that we want to return null if there is no match for the given input:
fun checkInput (data: String) : String { if(data == "Web") return "Web development" ...Read now
Unlock full access