Why can’t I return a concrete subtype of A if a generic subtype of A is declared as return parameter?

Method’s right hand side (pattern matching) t match { case Empty => Empty case NonEmpty(elem, left, right) => if (elem < 0) throw new Exception else NonEmpty(elem, assertNonNegatve(left), assertNonNegative(right)) } means to check at runtime whether t is an instance of class Empty$ (object Empty) and then choose the first branch or otherwise whether t … Read more