- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
What happens when I use the word "scala" in my package names? What is "_root_"?
Created by admin on 2008-07-28.
Updated: 2009-04-27, 16:25
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