That looks like the love child of an anonymous inner class and a closure.
Well, the following snippet:
produces: cool.Crazy$$anon$2@b162d5
and a similar thing happens when you create an actor
scala> val intActor = actor { react {
| case x: Int =>
| // I only want Ints
| println("Got an Int: "+x)
| } }
intActor: scala.actors.Actor =
scala.actors.Actor$$anon$1@34ba6b
(taken rom Artima's Programming in Scala book)
though I think in the actor example, actor is a static method on the Actor class that happens to return one of these weird anonymous things.
And the anonymous returned behaves just like a normal Actor:
scala.actors.Actor$$anon$3@1e4cbc4
hi, Peabody
The notation in your example is the same as:
def foo(arg:
String) = new
Object{ def printIt = println(arg) }
but I agree that AnyRef should be the more likely candidate since leaving "extends" off of a class definition implicitly extends AnyRef,
not Object. The Artima book (page 221) says the two can be used "interchangeably in Scala programs on the
Java Platform" but the "recommended style is to use AnyRef everywhere." The footnote points out: "The reason the AnyRef alias exists, instead of just using the name java.lang.Object, is because Scala was originally designed to work on both the Java and .NET platforms. On .NET, AnyRef is an alias for System.Object."
[ July 10, 2008: Message edited by: Marc Peabody ]