2 ms·
The only way b.length would compile, if b is a nullable array, is if it's defined in a Java class. In which case Kotlin will assume it's non-nullable in the abs
by Filligree 9y ago
The only way b.length would compile, if b is a nullable array, is if it's defined in a Java class. In which case Kotlin will assume it's non-nullable in the absence of nullability annotations. That is not perfectly ideal, but it's not Kotlin's fault; they decided (rightly, I think) that the reduced friction is worth the risk. And you can add annotations.
If b were defined in kotlin, as nullable, then b.length is a type error. You can use b?.length, or you can add an explicit null check and depend on the smart cast.