Scala import multiple packages

I have several Scala classes and objects in my own packages. Each package has a package object that defines some implications, therefore, for example, import com.foo.bar._imports all non-attendance and classes from the packagebar

I would like to know if there is a way to define “umbrella” imports, say com.foo.all, so

import com.foo.all._

equivalently

import com.foo.bar._
import com.foo.baz._
import com.foo.qux._
...

I can understand that this may be a little unclear, but if I consider the case where I have a large number of my own packages, it will be clearly more concise.

+5
source share
4 answers

The shortest form I can find:

import com.foo._, bar._, baz._, qux._

For instance:

import scala.collection.mutable._, PriorityQueue._, ArrayBuffer._

EDIT

, , @alex23, :

import com.foo.{foo, bar, baz}, bar._, baz._, qux._
+10

Scala / :

import scala.collection.immutable.{Map, HashMap, etc}

Scala : /

import java.util.{Collection => JavaCollection}
+7

, .

package object all ​​ ( ), , .

, , , .

import :

import com.foo.bar._, com.foo.baz._, ...

but all the ways to shorten the list further do not do exactly the same (for example, he will import the name barhimself, and not just its contents - this may not be a problem for you, but it is something conscious).

However, until the export mechanism appears, your code will be as readable and supported as possible if you print everything on your own line. It is much harder to notice something missing or added when everything is stuck on the same line.

+1
source

If bar._, baz._, qux._everything is in com.foo, than justcom.foo._

0
source

All Articles