Nullability
Some elements in Kotlin can be assigned a value of null, and some cannot. We say that the former are nullable and the latter are non-nullable. For example, while you might want a variable in NyetHack that tracks a player’s steed to be nullable, since not every player will ride a steed, you would not want the health points variable to be null. Every player has to have an associated health points value; it would be illogical for them not to. Its value might be 0, but 0 is not the same as null – null is the absence of any value.
Open NyetHack and create a new file called Tavern.kt. Add a main function, where your code will begin executing.
Before opening the tavern to custom drink requests from users, first try an experiment. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access