In scala Nothing
is a subtype of every other type.
scala> class A {}
defined class A
scala> def x[T >: Nothing](t: T): Unit = {}
x: [T](t: T)Unit
scala> x(new A)
When we create an arbitrary class, it automatically becomes a supertype of Nothing
- How this property is maintained in scala? Does the compiler makes
Nothing
extend every other class at compile time? - Like this way, is it possible to define a custom class
X
as a subtype of a set of classes(say set s) without makingX
extend from all the classes in the s? (e.g: ClassX
is a subtype of all the classes in packagecom.myproject.models
)
Please share your thoughts.