I have an actor that creates children actors of type Child1
in this example. Child1
constructor takes two String's which are extracted from variables that reside in SomeTrait
that is mixed into SomeActor
isntance.
trait SuperTrait {
lazy val str1: Option[String] = None
lazy val str2: Option[String] = None
}
trait SomeTrait extends SuperTrait {
override lazy val str1: Option[String] = Some("Str1")
override lazy val str2: Option[String] = Some("Str2")
}
class SomeActor extends Actor {
this: SuperTrait =>
var child: Option[ActorRef] = None
override def preStart(): Unit = {
child = for {
st1 <- str1
st2 <- str2
} yield context.actorOf(Child1.props(st1, st2)))
}
}
Creation on SomeActor
instance:
context.actorOf(Props[SomeActor with SomeTrait])
With this I am getting strange error:
SomeActor cannot be cast to SomeTrait
.
It seems that extracting variables from Option container of SomeTrait
throws that exception.
What am I missing here?
And it doesn't only happen with for comprehension
s. Also when I try to do str1.getOrElse("")
or add a getter to SomeTrait
: def getStr1 = str1.getOrElse("")