It may seem that we are just bringing back what we dropped before (and were so happy about it), but this is not so. If we neglected any of those, it would have been a compilation error. In the last line the compiler requires us to deal with both the argument of bar() requiring a non-null value (so we use “elvis” to provide a default) and the result being nullable (we use a safe call to guard from NPE). For example: // Javaįoo.bar(nullableString ?: "default")?.length() The details are described in this spec-document, but the overall idea is as follows: whenever we encounter nullability annotations in Java, and they do not conflict with anything around them (like overridden declarations in supertypes), we use precise types. ![]() Now, we are planning to make one more step and use annotations in combination with platform types to bring back as much type-safety as possible.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |