You can just ignore the aspects you don't care about. result
is a Bird
, so use it as one. That it is also a Product
and a Serializable
is not relevant (unless you want/need it to be). You can make it explicit by specifying its expected type:
val result: Bird = "test" match {
case s:String if s startsWith "t" => Eagle(5)
case _ => Sparrow(2)
}
Gives:
result: Bird = Eagle(5)
Or, you can assign it to another variable of type Bird
, or simply expect it to be a Bird
and charge ahead, calling methods defined on the Bird
trait, passing it as an argument to a function taking a parameter of type Bird
, etc.