In Scala, Nothing
is a bottom type, which means it is a subtype of every other type in the type system. It represents a data type that has no instances.
Essentially, 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
include: