I believe that we are misleading creation and announcement. Doc says that
Declaring one actor within another is very dangerous and breaks actor encapsulation. Never pass an actor's this reference into Props!
So, the problem is the declaration, not the creation! Let's take a look at Java:
public class MyActor extends AbstractActor { @Override public Receive createReceive() { return ReceiveBuilder.create() .match(String.class, handleString()) .matchAny(x -> unhandled(x)) .build(); } private FI.UnitApply<String> handleString() { return message -> sender().tell("OK", getSelf()); } class MyOtherActor extends AbstractActor { @Override public Receive createReceive() { return ReceiveBuilder.create() .match(String.class, handleString()) .matchAny(x -> unhandled(x)) .build(); } private FI.UnitApply<String> handleString() { return message -> sender().tell("OK-Inner", getSelf()); } } }
Now, if MyOtherActor was a normal class, we could only instantiate it from an instance of MyActor:
MyActor actor = new MyActor(); MyActor.MyOtherActor otherActor = actor.new MyOtherActor();
This means that the constructor for MyOtherActor depends on the instance of MyActor!
Now, if the props should contain the "factory" of the actor. They need a factory method. If our MyOtherActor is declared as we are here, then our details will look like this (ish):
MyActor actor = ??? // how did you even get a reference to the actor and not the actorRef in the first place! Props otherActorProps = Props.create(MyActor.MyOtherActor.class, () -> actor.new MyOtherActor());
And kick, here comes the kicker! Now your otherActorProps contains a link to actor , i.e. You have closed the variable state! If for any reason the actor "dies", your details will still refer to him, causing all sorts of oddities.
There is also a question about how you primarily get a link to actor , not actorRef
IMHO, what concerns the documentation, and not the fact of the "creation" (that is, the creation of an instance, spawning) of an actor in another: which is absolutely normal and this is a normal akka operation (that’s why you can do getContext().actorOf(..) , but also actorSystem.actorOf(...)