Chained Package Clauses

Martin Odersky

September 7, 2010

If you have already looked at some larger Scala 2.8 programs you might have been puzzled to see that source files now sometimes start with multiple chained package clauses, like this:

package org.myproject
package tests

What does this mean? In fact it means exactly the same as writing two nested package clauses, like this:

package org.myproject {
  package tests {

Nested package clauses, while perfectly legal, are not used that often in Scala because their syntax is more heavyweight than single or chained package clauses. Their advantage is that they make the nesting structure of packages explicit. But before Scala 2.8, most programmers would have opted for a single package clause like this:

package org.myproject.tests

Next: What Has Changed