views:

191

answers:

3

Simple question. Can I do this:

object Xyz extends Actor { ... }

or do Actors have to be classes with instances?

+3  A: 

The object keyword is essentially creating an anonymous class and a single instance of that class. So yes, that code will be fine - Xyz will be a reference to an object that is an Actor.

Lachlan
Thanks, that's what I thought. I did try this and it compiled fine, but the messages don't seem to be getting received by the actor.
Joe
Looks like that problem was unrelated to `object` or not. Solved.
Joe
with scala 2.8, I get this error:object creation impossible, since method act in trait Reactor of type ()Unit is not defined
Aaron
+1  A: 

I would like to recommend the following 'fire and forget' pattern:

Actor.actor { doStuff }

Your operation will run in a separate thread to conclusion.

Fred Haslam
+4  A: 

Object extending Actor works fine.

Perhaps you forgot to start the actor? (That's a mistake I did initially)

object Xyz extends Actor {
    start

    ...
}
HRJ
Yep, I had forgotten to start the actor (but was too embarrassed to say...). Thanks!
Joe