badcosmetics.blogg.se

Kotlin nullable
Kotlin nullable









kotlin nullable

Println(s1.length) // will never throw NPE Var s2: String? = "abc" // s2 is nullable

kotlin nullable kotlin nullable

Var s1: String = "abc" // s1 is not nullable So, for example, in Kotlin, a variable of type String can never be null, but a variable of type String? (note ? suffix) can. The Kotlin type system distinguishes between references that can hold null values (nullable references) and those that can't, and the compiler will verify consistent usage of variables of each type. More than any other language I have used, Kotlin greatly reduces occurrences of the dreaded NullPointerException. One of the major design goals of Kotlin was to eliminate, or at least greatly reduce problems associated with null references.











Kotlin nullable