I have the following code:
val fsm = TestFSMRef(new SenderCollectorFsm)
And do not understand, why do I have to pass to TestFSMRef
an instance.
Lets look at the definition of TestFSMRef:
object TestFSMRef {
def apply[S, D, T <: Actor: ClassTag](
factory: => T)(implicit ev: T <:< FSM[S, D], system: ActorSystem): TestFSMRef[S, D, T] = {
val impl = system.asInstanceOf[ActorSystemImpl]
new TestFSMRef(impl, Props(factory), impl.guardian.asInstanceOf[InternalActorRef], TestActorRef.randomName)
}
T
is subtype of Actor
and ClassTag
, but how to know, that T
has to be an object?
Scala is an object-oriented language. Like in almost all object-oriented languages, you can only pass objects as arguments. Also, like most languages, types aren't objects.
So, since you can only pass objects, and types aren't objects, it is clear that you can only pass an instance.
Or, to be more precise: there exist two separate universes, the universe of types and the universe of values. In the universe of values, we have methods which take values as arguments in round parentheses (or occasionally curly braces).
In the universe of types, we have type constructors, which take types as arguments in square brackets.
There is exactly one place where the two universes meet, and that is in path-dependent types.