For the More Curious: The Nothing Type
In this chapter you learned about the Unit type and that a function of the Unit type returns no value.
Another type that is related to Unit is the Nothing type. Like Unit, Nothing indicates that a function returns no value – but there the similarity ends. Nothing lets the compiler know that a function is guaranteed to never successfully complete; the function will either throw an exception or for some other reason never return to where it was called.
What is the use of the Nothing type? One example of Nothing’s use is the TODO function, included with the Kotlin standard library.
Take a look at TODO by pressing the Shift key twice to open the Search Everywhere dialog and entering its name. ...
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