October 2019
Intermediate to advanced
434 pages
11h 54m
English
With a non-null type, you may safely call methods or access properties on a variable without worrying about NullPointerException. In this snippet, languages is inferred to be List<String>. Because languages is of a non-null type, the isNotEmpty() method may be called without worrying about NullPointerException, as follows:
fun main(args: Array<String>) { var languages = listOf("Kotlin", "Java", "c++") languages.isNotEmpty() // okay}
If the list were defined as List<String>?, this would not be the case. In this case, calling companies.isNotEmpty() would result in a compiler error. Because the compiler knows the value might be null, it will require you to handle that possibility in some way:
fun main(args: Array<String>) {
Read now
Unlock full access