I’m writing a ScalaTest JMock expectation. The syntax is usually
expecting { e => import e._
// call methods on e
}
Now I happen to know that e is a subclass of Expectation. I can write
expecting { e =>
val e2 = e.asInstanceOf[MySubclass]
import e2._
// call MySubclass methods
}
but I can’t find any way of making a one-liner like
expecting { e => import (e.asInstanceOf[MySubclass])._
// call MySubclass methods
}
compile.
Is there anyway to combine down-casting and importing in a single step?
I don´t see a way to combine both, but I would rather implement it like this: