![]() Writing an if-not-null check is easy, but the problem is the (implicit) else that comes with it. You may be tempted to write, just to be safe, null-checks anyway, but it would not serve you well. For example, when your customer may or may not have an email, you will have defined how to contact him in either case.įor mandatory attributes, on the other hand, we generally don’t define what should happen if the value is absent (because, well, that should never happen). Not knowing whether a variable can be null or not is.įrom a design perspective, when you have an optional attribute, you will have specified how to deal with its absence. The problem in an object-oriented language like Java is that all types are nullable and that there is no native way to express that a variable is never null. ![]() While null references have been called a “billion-dollar mistake”, null to represent absence of value is an important concept. ![]() ![]() In this article we will look at one of the main reasons for using Kotlin over Java: Null Safety. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |