Kotlin Nullable and Non-Nullable types


Normal types, like String, are not nullable. To make them able to hold null values, you have to explicitly denote that by putting a ? behind them: String?

var string        : String = "Hello World!"
var nullableString: String? = null

string = nullableString    // Compiler error: Can't assign nullable to non-nullable type.
nullableString = string    // This will work however!