You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Null Safety
In an effort to rid the world of NullPointerException, variable types in Kotlin don't allow the assignment of null. If you need a variable that can be null, declare it nullable by adding ? at the end of its type.
fun main() {
//sampleStart
var neverNull: String = "This can't be null" // 1
neverNull = null // 2
var nullable: String? = "You can keep a null here" // 3
nullable = null // 4
var inferredNonNull = "The compiler assumes non-null" // 5
inferredNonNull = null // 6
fun strLength(notNull: String): Int { // 7
return notNull.length
}
It should be this in documentation :
println(strLength(neverNull)); // 8
println(strLength(nullable)); // 9
Null Safety
In an effort to rid the world of NullPointerException, variable types in Kotlin don't allow the assignment of null. If you need a variable that can be null, declare it nullable by adding ? at the end of its type.
fun main() {
//sampleStart
var neverNull: String = "This can't be null" // 1
It should be this in documentation :
println(strLength(neverNull)); // 8
println(strLength(nullable)); // 9
instead of this:
strLength(neverNull) // 8
strLength(nullable) // 9
//sampleEnd
}
i have already created the pull request for this.
The text was updated successfully, but these errors were encountered: