I'm using IntelliJ IDEA with the Scala plugin. If I reference HashMap in code, and then use Alt-Enter to add the import, the package gets imported as:
_root_.scala.collection.immutable.HashMap
What's the root part of this? It seems to work with and without it.
Package in Scala is a mechanism to encapsulate a group of classes, sub packages, traits and package objects. It basically provides namespace to put our code in a different files and directories. Packages is a easy way to maintain our code which prevents naming conflicts of members of different packages.
Scala provides package objects as a convenient container shared across an entire package. Package objects can contain arbitrary definitions, not just variable and method definitions. For instance, they are frequently used to hold package-wide type aliases and implicit conversions.
It has to do scala imports being relative - _root_
gives you a way to specify an absolute package name. See the Scala Wiki
The Scala language specification has this to say about _root_
in section 9.4 Package References
The special predefined name
_root_
refers to the outermost root package which contains all top-level packages.
See the following PDF for the full language reference: http://www.scala-lang.org/docu/files/ScalaReference.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With