Nothing
is a special class in Kotlin. One use of Nothing
is as a return
type — this indicates that the function will never return normally.
Typically, this is because the function always throws an exception. The TODO()
function in standard Kotlin works this way, as does the NOTDONE()
analogue
shown here.
Even though heyThisIsNotDoneYet()
is set to return an Int
,
and there is no return
statement, this sample compiles and runs. The
reason is because Kotlin sees that NOTDONE()
returns Nothing
, and therefore
the entire rest of the heyThisIsNotDoneYet()
function after the NOTDONE()
call is meaningless, as NOTDONE()
will never return.
You can learn more about this in:
Tags: