One more baby step into Scala, in this second of a series of posts. Import statements.
Scala’s import statements are very similar to Java’s, but with some small differences that allow you to write more concise code. Take a look at the following examples:
1. _ instead of *
Java:
import java.util.*;
Scala:
import scala.util._
2. Importing multiple classes from the same package
Java:
import java.util.Date; import java.util.Collection; import java.util.List;
Scala:
import java.util.{Date, Collection, List}
3. Renaming
Java:
// can't be done
Scala:
import java.util.{Collection => JavaCollection}
Although I used Java classes in almost all the examples above, you can of course use the same syntax for all the Scala classes as well.
That’s all for now! What do you want to read next about Scala? Leave a comment!
Nice!