uraj uraj - 1 month ago 16
Scala Question

Is it possible to define a bottom class in a sublattice of Scala's type hierarchy?

Say I have an abstract class

A
. Now I want to define a final class
ABot
such that for any class
B
that extends
A
(except
Nothing
),
ABot
is a subclass of
B
. It's just like
Nothing
, but with respect to the hierarchy where
A
is the top.

Answer

Answer is No.

A class will not be a subtype of X unless you explicitly extend X.

scala.Nothing is an exception because Scala compiler does the magic for you.