-
Book Overview & Buying
-
Table Of Contents
Kotlin for Java Developers
By :
Many times, when we talk about a feature of a programming language, we expect it to refer to just a character or a line of code. That is why when programmers are introduced to the concept of null safety, they are initially a little confused since it is not just one thing. Null safety is a concept encapsulating a set of characteristics of the programming language that are designed to prevent errors that can cause null references. These errors, as we are aware, are known as NPEs, and they occur at runtime.
Something we have already seen that we can include as part of null safety is the ability to have null and non-null types. It is very easy to distinguish whether we can have null by simply knowing the type, since if it is not of the nullable type, then we know that it cannot be null.
The following is example code with non-nullable types:
fun main(args: Array<String> ){
var name: String = "Jose"
var age: Int = 10
var height: Double...