![]() One thing I try and do (and I remember someone else saying the same on this forum recently) is to use references to ‘default’ objects rather than null whenever possible. ![]() My personal view is that we’ll never be able to eliminate the need for null entirely. So I think what we have at present is a reasonable balance which can be overridden using the aforementioned features when it seems appropriate to do so. It may be that the compiler could be made smarter as regards null checking but only at the expense of having complicated rules or flow analysis which will inevitably slow down the compilation process. If the programmer is wrong about this then he/she will, of course, be punished with an exception. Well, as we’re often reminded, Kotlin is intended to be a pragmatic rather than a purely academic language and it seems to me that the existence of features such as 'lateinit' and '!!' is just an acknowledgement that sometimes the programmer will know better than the compiler about whether an object reference is going to be null or not.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |