What you face here is an interesting detail of scala and nested classes. When you have a construct like
class Foo {
class Bar
}
then the inner class Bar
will be bound to a specific instance of Foo, meaning you can't instantiate it outside of this instance.
scala> new Foo
res5: Foo = Foo@5b2cef50
scala> new res5.Bar
res6: res5.Bar = Foo$Bar@64f8b658
scala> new Foo#Bar
<console>:12: error: Foo is not a legal prefix for a constructor
new Foo#Bar
^
The Props.apply[A <: Actor]
implicitly retrieves an instance of ClassTag[A]
an then tries to call the constructor through reflection. So let's have a look at the constructors of Foo#Bar
:
scala> classOf[Foo#Bar].getConstructors
res9: Array[java.lang.reflect.Constructor[_]] = Array(public Foo$Bar(Foo))
As you can see, it expects an instance of Foo
as parameter. So how do we fix this?
My suggestion would be to just take the class outside of the test class. There are 2 possibilities, either put it directly under the package, as your other class, or put in in the companion of the test class.
Another way to fix this would be to pass a reference to the test class to the Props
:
system.actorOf(Props(classOf[MyOtherGreeter], this), "other")