Number not assignable from Nothing

I was surprised to see these results. Why is Nothing not assignable from Number? and also Number not assignable from Nothing ?
Is this a special case because Nothing is not assignable?

classOf[java.lang.Number].isAssignableFrom(classOf[java.lang.Long])
==> true
classOf[java.lang.Long].isAssignableFrom(classOf[java.lang.Number])
==> false
classOf[Nothing].isAssignableFrom(classOf[java.lang.Number])
==> false
classOf[java.lang.Number].isAssignableFrom(classOf[Nothing])
==> false

Classes are NOT Types.

Nothing is a subtype of all values, but it IS NOT a subclass of all classes.

2 Likes

I’m a bit surprised this (scala.runtime.Nothing$) even exists! Anyone know what it’s for?

In any case, as Luis indicates, Nothing being a bottom type is a fact about the Scala type system that there’s no possibility of tricking Java reflection into understanding.

1 Like

Dummy class which exist only to satisfy the JVM.:slight_smile:

2 Likes

Ah, “If such type appears in method signatures, it is erased to this one”, that makes sense, every type must erase to something. (And erasing to Object instead would allow invalid calls from Java code.)