Scala: What is the Nothing data type?
Scala FAQ: What is the Nothing
type in Scala, and how do I use it?
Solution
In Scala, Nothing
is called a bottom type, which means it is a sub-type of every other type in the Scala type system. It is also specifically a data type that has no instances.
In practical use, Nothing
is used to indicate that a computation or function will never produce a result normally, either because it throws an exception, enters an infinite loop, or encounters some other abnormal termination.
Visually, this is what the Nothing
type looks like in the Scala type hierarchy (image courtesy of this scala-lang.org page):
Scala: Common uses of Nothing
Some common use cases of Nothing
in Scala include: