DEV Community

Discussion on: Simple, yet powerful features of Kotlin

Collapse
 
vladrassokhin profile image
Vladislav Rassokhin

In Kotlin, by default the variables var is of non-null type.
If you really want to allow type to accept 'null' values, you must explicitly states so as below using '?' operator.

Please do not misinform readers, it not by default and definitely not an '?' operator. (Operators cannot be applied to types). It's part of type system where '?' in the end of type denotes reference as nullable and without - non-null references.
Here's proper explanation of nullability in Kotlin.

Actually nullability-related operators are ?., !!., ?: and as?.

Collapse
 
subbramanil profile image
Subbu Lakshmanan

Thank you Vladislav Rassokhin for the feedback. I have updated the blog as per the comments.

Collapse
 
humzakhan profile image
Humza K.

"Please do not misinform readers" That's harsh. He didn't do it intentionally. As he mentioned, he's currently learning the language himself. Why are you being intentionally rude then?

Collapse
 
nebtrx profile image
Omar 👾λmed • Edited

Agreed. That's harsh!. Anyway, String? is actually syntactic sugar for something like Nullable<String>. It's an idea taken from Maybe polymorphic data type, which is very popular in Functional Languages like Haskell.