This page is no longer maintained — Please continue to the home page at www.scala-lang.org

What happens when I use the word "scala" in my package names? What is "_root_"?

Unlike Java, Scala has relative package names. For instance, you could write

package com.mycompany.tools;
  import mycompany._;
  // ..

which would import everything in package com.mycompany. The problem is that the import statement

  import scala.collection.mutable.ArrayBuffer

then also looks in your package scala, not the global one which is further outside, in the hierarchy.

The advantage of this scheme is that package names need not be absolute, therefore they can be shorter, and more easily adapted when you move things from one package to another.

You can still use an absolute package name in Scala, however, by simply prepending your package name with the special _root_ path, as follows:

import _root_.scala.collection.mutable.ArrayBuffer

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland