Suppose I have a non-sealed trait A and need a function convert[T <: A]: A => Option[T]:
def convert[T <: A](a: A): Option[T] = // don't compile
if (a is instance of T) then Some(a) else None
How would you suggest implement that convert ?
P.S I don't like reflection but need to deal with legacy, which uses it.
Aucun commentaire:
Enregistrer un commentaire