Packages and package objects
Just like Java, a is a special container or which contains/defines a set of objects, classes, and even packages. Every Scala file has the following automatically imported:
java.lang._
scala._
scala.Predef._
The following is an example for basic imports:
// import only one member of a package import java.io.File // Import all members in a specific package import java.io._ // Import many members in a single import statement import java.io.{File, IOException, FileNotFoundException} // Import many members in a multiple import statement import java.io.File import java.io.FileNotFoundException import java.io.IOException
You can even rename a member while importing, and that's to avoid a collision between packages that have the same member name. This method is also called class alias
:
import java.util.{List => UtilList} import java.awt.{List => AwtList} // In the code, you can use the alias that you have created val list = new UtilList
As mentioned in Chapter 1, Introduction...