by dullgiulio · 9y ago · 0 comments
Unline Kotlin, Go does support len() (.length in Kotlin) on nil: https://play.golang.org/p/koqYbIdltw
In Kotlin, b.length can throw a NPE, only a b?.length won't (it will return zero or null, I have not understood that).
Together with the var/val debacle, it seems like it is designed to be very terse, which can lead to easier errors.
I don't think it solves the 1M$ mistake at all. And how could it, while maintaining full compatiblity with Java?
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.