Scala - Import

Card Puncher Data Processing


In Scala, everything can be imported to make code available in your code (not only class names)


when importing all the names of a package or class, scala uses the underscore character _ instead of the java asterisk *. That’s because the asterisk is a valid Scala identifier (e.g. method name)


package will be available in your code.



With the object baz in package, the following would import all the members of that object.


The import statement imports all members of the class. This makes visible:

  • the static method
  • and the static fields


If you define a class MyClass in package, you can import that specific class (and not anything else from that package) with


Multiple classes can be imported from the same package by enclosing them in curly braces:

import java.util.{Date, Locale}

Discover More
Card Puncher Data Processing
Scala - Java

All classes from the java/lang/package-summaryjava.lang package are imported by default, while others need to be imported explicitly. Java’s class libraries define powerful utility classes, such...

Share this page:
Follow us:
Task Runner