Reputation: 3201
If Nothing
is a child class of AnyVal
including Unit
, then why I cannot assign Nothing
to oh
?
import scala.Nothing
val oh: Unit = Nothing
Upvotes: 2
Views: 549
Reputation: 55569
It's right in the scaladoc.
Nothing is a subtype of every other type (including scala.Null); there exist no instances of this type.
If there are no instances of Nothing
, you cannot assign it to anything. It's not a value.
Upvotes: 8
Reputation:
Nothing
is a type, not a value. You can only assign values to variables.
Upvotes: 5