What does the "extends {..}" clause do in a Scala object definition without a superclass name?

I found this sample code in a Program in Scala, 2nd Ed. (Chapter 25, listing 25.11):

object PrefixMap extends { def empty[T] = ... def apply[T](kvs: (String, T)*): PrefixMap[T] = ... ... } 

Why is there an extends clause without a superclass name? This is like extending an anonymous class, but for what purpose? The accompanying text does not explain or even mention this construction anywhere. The code really compiles and seems to work just fine with or without it.

OTOH I found the same code on several web pages, including this one (which looks like the original version of a chapter in a book), I doubt that a typo could go below the radars of so many readers so far ... so I'm not enough?

I tried to do this, but struggled to find the right search terms. So can anyone explain if this construct has a name and / or practical use in Scala?

+6
source share
1 answer

Sounds like a printing error. This will still work, although it probably helped to hide all this time.

In any case, this object extends the structural type, although it can also be early initialization if you have with XXX at the end. Mmmmm. This is more like early initialization without any classes or attributes that will be initialized later, in fact ... the structure types do not contain code, I think.

+3
source

All Articles