🐦 Kotlin
Beginner
What is the Nothing type in Kotlin?
Answer
Nothing is a type with no instances — a function that returns Nothing never returns normally. It is used for functions that always throw an exception or loop forever: fun fail(msg: String): Nothing = throw IllegalStateException(msg). Nothing is a subtype of every type, which means it can be used anywhere any type is expected. This is why throw expressions are valid in places like the Elvis operator: val name = user?.name ?: throw RuntimeException(). The TODO() function also returns Nothing, signaling unimplemented code.
Previous
What does the Any type represent in Kotlin?
Next
What is destructuring declaration in Kotlin?