trait Either trait Left: Either trait Right: Either class C1(val v1: Int) class C2(val v2: Int) fun _as_left(e: Either): Any? { val v = e as? Left return v: Left? } fun _as_right(e: Either): Any? { val v = e as? Right return v: Right? }