The striking thing happens if we try to call a method/field on the second one – the code doesn’t compile: foo2.length So, that’s non-nullable String: val foo : String = "42"Īnd this one is nullable: val foo2 : String? = "42"Īs simple as it is. Simply put, each type is non-nullable by default but can be made nullable by appending the question mark to the type name. Kotlin implemented its approach to null-safety that can leverage extra compiler support. If you’re familiar with Kotlin’s approach to null-safety, feel free to skip this section with no regrets. Let’s see how does its native approach to null-safety compare to. Kotlin truly shines when it comes to avoiding excessive bureaucracy of classical Type-Driven approaches to optionality.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |