November 2018
Intermediate to advanced
388 pages
9h 5m
English
Generally, when we write code, we declare the fields in a class. We are not sure whether or not the field is initialized during execution. To find out, we use null checks and annotations such as @Nullable or @NotNull. Kotlin provides elegant syntax for declaring fields with nullable and non-nullable types, which prevents the problem of accidental NullPointerExceptions (NPEs). Kotlin catches possible null pointers when the code is being compiled, meaning that no null pointer issues will occur after the application has been deployed. This means that there are almost no cases of NullPointerException.
Consider the following code:
object NullabilityTest {
@JvmStatic
fun main(args: Array<String>) {
var msg: String = null println(msg) ...Read now
Unlock full access