I have some cases where I’d like methods to return either type A or some type B (A and B are some classes, like String and Int)?
You can use an Either type and pattern matching
sealed trait Either[A,B] case class Left[A,B](x:A) extends Either[A,B] case class Right[A,B](x:B) extends Either[A,B]
Or you can use “dynamic typing”
def foo(): AnyRef // should be: either A or B foo() match { case a: A => ... case b: B => ... }